In [323]: arr = np.arange(12).reshape(3,4)
In [324]: alist = list(range(3))
In [325]: np.concatenate((arr,alist))
-
ValueError Traceback (most recent call last)
<ipython-input-325-9b72583c40de> in <module>()
> 1 np.concatenate((arr,alist))
ValueError: all the input arrays must have same number of dimensions
In [326]: arr.shape
Out[326]: (3, 4)
听起来你的列表在变成数组时,没有正确的维数。让我举例说明:
^{pr2}$concatenate
将任何列表输入转换为数组:arr
是2d,因此此数组也需要是2d的:将(3,4)数组与最后一维上的(3,1)数组连接起来很容易。在
我得到的印象是,很多人在没有理解numpy数组的一些基础知识(比如形状和尺寸)的情况下,就开始使用机器学习代码(
tensorflow
,keras
,sklearn
)。在相关问题 更多 >
编程相关推荐