Numpy list of 1D Arrays to 2D Array Numpy list of 1D Arrays to 2D Array numpy numpy

Numpy list of 1D Arrays to 2D Array


You can use

numpy.stack(arrays, axis=0)

if you have an array of arrays. You can specify the axis in case you want to stack columns and not rows.


The array may be recreated:

a = np.array(a.tolist())


You can just call np.array on the list of 1D arrays.

>>> import numpy as np>>> arrs = [np.array([1,2,3]), np.array([4,5,6]), np.array([7,8,9])]>>> arrs[array([1, 2, 3]), array([4, 5, 6]), array([7, 8, 9])]>>> arr2d = np.array(arrs)>>> arr2d.shape(3, 3)>>> arr2darray([[1, 2, 3],       [4, 5, 6],       [7, 8, 9]])