Numpy 如何重新排列行?

Numpy 如何重新排列行?,numpy,recarray,Numpy,Recarray,默认的recarray迭代器似乎正在遍历列。是否有一个对应于pandas的迭代行视图的iterrows/itertuples?当您使用时,dtype是什么?重新排列实际上没有形状。数据类型是[('fieldname','O')]*n_字段。记录具有数据类型,但重新排列,结构化数组上的变体也具有形状。当数组是2d时,列和行是有意义的。一个小例子可能会有所帮助。 In [102]: np.dtype('O,O,O')

默认的
recarray
迭代器似乎正在遍历列。是否有一个对应于pandas的迭代行视图的
iterrows
/
itertuples
?当您使用时,
dtype
是什么?重新排列实际上没有形状。数据类型是
[('fieldname','O')]*n_字段
记录
具有数据类型,但
重新排列
,结构化数组上的变体也具有形状。当数组是2d时,列和行是有意义的。一个小例子可能会有所帮助。
In [102]: np.dtype('O,O,O')                                                     
Out[102]: dtype([('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [103]: dt = np.dtype('O,O,O')                                                
In [104]: np.recarray((4,), dt)                                                 
Out[104]: 
rec.array([(None, None, None), (None, None, None), (None, None, None),
           (None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [105]: arr = np.recarray((4,), dt)                                           
In [106]: arr                                                                   
Out[106]: 
rec.array([(None, None, None), (None, None, None), (None, None, None),
           (None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [107]: arr.f0                                                                
Out[107]: array([None, None, None, None], dtype=object)
In [108]: arr['f0']                                                             
Out[108]: array([None, None, None, None], dtype=object)
In [109]: for i in arr: print(repr(i))                                          
(None, None, None)
(None, None, None)
(None, None, None)
(None, None, None)
In [110]: arr = np.recarray((4,1), dt)                                          
In [111]: arr                                                                   
Out[111]: 
rec.array([[(None, None, None)],
           [(None, None, None)],
           [(None, None, None)],
           [(None, None, None)]],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [112]: for i in arr: print(repr(i))                                          
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])