Flattening a list of NumPy arrays?

前端 未结 5 1597
别那么骄傲
别那么骄傲 2020-12-01 06:13

It appears that I have data in the format of a list of NumPy arrays (type() = np.ndarray):

[array([[ 0.00353654]]), array([[ 0.00353654]]), arra         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 06:40

    Another simple approach would be to use numpy.hstack() followed by removing the singleton dimension using squeeze() as in:

    In [61]: np.hstack(list_of_arrs).squeeze()
    Out[61]: 
    array([0.00353654, 0.00353654, 0.00353654, 0.00353654, 0.00353654,
           0.00353654, 0.00353654, 0.00353654, 0.00353654, 0.00353654,
           0.00353654, 0.00353654, 0.00353654])
    

提交回复
热议问题