np.rec.fromarrays我已經建立了一個具有以下結構的recarray :
dtype=np.dtype([('layers', 'U256'), ('hours', datetime.datetime), ('points', 'U256')]))
我得到一個像這樣的物件:
[('image1.jpg', datetime.datetime(1900, 1, 1, 21, 20), 'mypoints.points')
('image2.jpg', datetime.datetime(1900, 1, 1, 21, 15), 'mypoints.points')]
與recarray型別。我想根據包含datetime. 我試過numpy.recarray.sort了,但它回傳一個 NoneType 物件。我這樣使用它:
mytable.sort(order='hours')
我也嘗試傳遞kind='quicksort'給該函式,但不了解它的用處。
uj5u.com熱心網友回復:
我試圖重現你的資料
x1=np.array(['image1.jpg', 'image2.jpg'])
x2=np.array([datetime.datetime(1900, 1, 1, 21, 10), datetime.datetime(1900, 1, 1, 21, 9)])
x3=np.array(['mypoints.points', 'mypoints.points'])
array = np.rec.fromarrays([x1, x2, x3], dtype=np.dtype([('layers', 'U256'), ('hours', datetime.datetime), ('points', 'U256')]))
輸出:
rec.array([('image1.jpg', datetime.datetime(1900, 1, 1, 21, 20), 'mypoints.points'),
('image2.jpg', datetime.datetime(1900, 1, 1, 21, 15), 'mypoints.points')],
dtype=[('layers', '<U256'), ('hours', 'O'), ('points', '<U256')])
但無法得到同樣的錯誤......array.sort(order='hours')作業正常
rec.array([('image2.jpg', datetime.datetime(1900, 1, 1, 21, 15), 'mypoints.points'),
('image1.jpg', datetime.datetime(1900, 1, 1, 21, 20), 'mypoints.points')],
dtype=[('layers', '<U256'), ('hours', 'O'), ('points', '<U256')])
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/471414.html
標籤:python-3.x 麻木的 排序 约会时间 重新排列
