Numpy: Create a 1D array of numpy arrays when all arrays have the same length

前端 未结 4 780
有刺的猬
有刺的猬 2021-01-14 05:48

I want to be able to convert an existing 2D array to a 1D array of arrays. The only way I can find is to use something like:

my_2d_array = np.random.random((         


        
4条回答
  •  滥情空心
    2021-01-14 06:22

    Simply you could call ravel() to convert any dimension arrays to 1d.

    my_converted_array = np.ravel(my_2d_array)
    

    Learn more about ravel() here.

    Or you could simply use:

    my_converted_array = my_2d_array.reshape(-1)
    

提交回复
热议问题