首页 > 解决方案 > ValueError:无法将 NumPy 数组转换为张量(不支持的对象类型 numpy.ndarray)。在 jupyternotebook

问题描述

我在 jupyter 中编写代码

print('---------------Data Gathering------------------')
# put The address of test images
directory_location_test = "G:\\ml\\test"
data_test, labels_test = data_extraction(directory_location_test)
testX = np.array(data_test)
#testX = tf.convert_to_tensor(testX)
#testX = testX.astype('int32')

testY = labels_test

但在我的代码显示

<ipython-input-5-9ba842610e7d>:60: 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.
  testX = np.array(data_test)

和错误:请我解决

标签: pythonnumpy

解决方案


使用加载的数据似乎data_extraction()不像弃用错误所说的那样具有统一的大小:Creating an ndarray from ragged nested sequences.

输入数据沿某个轴可能具有不同的长度,例如。data = [[1], [1,2]]

如果没有关于“data_extraction()”是什么的信息,我真的无能为力。


推荐阅读