Home>

I want to do something like listing a multidimensional array with numpy.

arr_list = np.array ([])
for k in range (3):
    data = randint (-20, 20, 80)
    # 20x4 matrix
    arr = data.reshape (20, 4)
    arr_list = np.stack ([arr_list, arr])


After executing the above code,

ValueError Traceback (most recent call last)
<ipython-input-145-74f701246da9>in<module>()
---->1 z_list = np.stack ([z_list, z1])
~/.pyenv/versions/3.6.1/lib/python3.6/site-packages/numpy/core/shape_base.py in stack (arrays, axis, out)
    414 shapes = {arr.shape for arr in arrays}
    415 if len (shapes)! = 1:
->416 raise ValueError ('all input arrays must have the same shape')
    417
    418 result_ndim = arrays [0] .ndim + 1
ValueError: all input arrays must have the same shape


Np.stack could not be used with an empty array.

I want to list a 20x4 matrix so that it looks like arr_list.shape (3, 20, 4).
If arr_list [0] is specified, the ideal mechanism is to extract the first created matrix.

How can it be realized?