ndarray的Numpy堆栈列表

时间:2018-02-17 20:57:24

标签: python-2.7 list numpy opencv multidimensional-array

我有一个形状为(3, 64, 64)的图片列表,读取它们并将它们存储在列表images中。 然后我将堆栈应用到List:

images = np.stack(images)

我收到了这个错误:

 File "/usr/local/lib/python2.7/dist-packages/numpy/core/shape_base.py", line 350, in stack
raise ValueError('need at least one array to stack')
ValueError: need at least one array to stack'

我将很感激有任何人对此有所了解。

1 个答案:

答案 0 :(得分:1)

我可以通过以下方式重现您的错误:

In [94]: images=[]
In [95]: np.stack(images)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-95-adab3e1812bc> in <module>()
----> 1 np.stack(images)

/usr/local/lib/python3.5/dist-packages/numpy/core/shape_base.py in stack(arrays, axis, out)
    347     arrays = [asanyarray(arr) for arr in arrays]
    348     if not arrays:
--> 349         raise ValueError('need at least one array to stack')
    350 
    351     shapes = set(arr.shape for arr in arrays)

ValueError: need at least one array to stack

它会引发错误,因为这是True

In [97]: not images
Out[97]: True