Python List of np arrays to array

前端 未结 3 380
无人及你
无人及你 2020-12-30 19:22

I\'m trying to turn a list of 2d numpy arrays into a 2d numpy array. For example,

dat_list = []
for i in range(10):
    dat_list.append(np.zeros([5, 10]))
         


        
相关标签:
3条回答
  • 2020-12-30 19:30

    See https://docs.scipy.org/doc/numpy/reference/generated/numpy.append.html for details. You can use append, but will want to specify the axis on which to append.

    dat_list.append(np.zeros([5, 10]),axis=0)
    
    0 讨论(0)
  • 2020-12-30 19:41

    you want to stack them:

    np.vstack(dat_list)
    
    0 讨论(0)
  • 2020-12-30 19:41

    Above accepted answer is correct for 2D arrays as you requested. For 3D input arrays though, vstack() will give you a surprising outcome. For those, use stack(<list of 3D arrays>, 0).

    0 讨论(0)
提交回复
热议问题