Visible Deprecation Warning: Creating an ndarray from ragged nested sequences (which is list or tupl

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes)is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.

  • 问题
  • 原因
  • 解决办法


禁止转载!

问题

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

原因

这是因为新的numpy版本,将 创建不同长度或形状的列表或元组或ndarray的列表或ndarray元组的功能 会被弃用,虽然能够运行,但是总提示Warning还是很不舒服,况且之后也不能这样用了。
这里先复现一下错误,让大家更好理解:

import numpy as np
test_list=[[12,12],[1,2],[0]]
bboxes = np.array(test_list)
print(bboxes)

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify ‘dtype=object’ when creating the ndarray.
bboxes = np.array(test_list)

解决办法

  1. 方法一:使用更早的numpy版本
  2. 方法二:加上’dtype=object’
bboxes = np.array(test_list,dtype=object)

禁止转载!

你可能感兴趣的:(python,python,numpy)