我有一个numpy结构化数组,其中一列名为'time',我希望限制'time'
列在某个范围内的数据。我试过这个:
time_restricted_data = Data[ (Data['time'] > 0.6) & (Data['time'] < 0.7) ]
但是返回了Data['time'] > 0.6
的所有数据。
有什么建议吗?
答案 0 :(得分:1)
你的例子有些不对劲,即我无法确认,我认为你写的内容应该按预期工作:
In [19]: Data = np.zeros(100,dtype=[('time', np.float), ('y',np.float)])
In [20]: Data['y'] = np.random.uniform(size=100)
In [21]: Data['time'] = np.random.uniform(size=100)
In [22]: print Data[ (Data['time'] > 0.6) & (Data['time'] < 0.7) ]
[(0.6309334093696576, 0.5898588768194092)
(0.6026040512366535, 0.4260650141076221)
(0.6587399844526572, 0.033397798015253444)
(0.6863639946779522, 0.67002523603246)
(0.6522035987367735, 0.948019085443445)
(0.6809894254849801, 0.5131390279565994)
(0.6311277013562147, 0.5746610745753917)
(0.6324174554481182, 0.8587836614681397)
(0.6542221804687635, 0.9706926940115863)
(0.671321726341415, 0.7446681474117195)]