Converting a 2D numpy array to a structured array

前端 未结 5 1683
故里飘歌
故里飘歌 2020-11-29 01:08

I\'m trying to convert a two-dimensional array into a structured array with named fields. I want each row in the 2D array to be a new record in the structured array. Unfortu

5条回答
  •  日久生厌
    2020-11-29 01:43

    I guess

    new_array = np.core.records.fromrecords([("Hello",2.5,3),("World",3.6,2)],
                                            names='Col1,Col2,Col3',
                                            formats='S8,f8,i8')
    

    is what you want.

提交回复
热议问题