lafi raed
lafi raed

Reputation: 113

Numpy stack list of ndarray

I have a list of images that have a shape of (3, 64, 64), read them and store them in a List images. Then i applied stack to the List :

images = np.stack(images)

i got this error :

 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'

I will be grateful to have anyone's idea about this.

Upvotes: 0

Views: 535

Answers (1)

hpaulj
hpaulj

Reputation: 231395

I can reproduce your error with:

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

It raises the error because this is True:

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

Upvotes: 1

Related Questions