0

I have a numpy structured array with one of the columns called 'time' I want to restrict my data where the 'time' column is in a certain range. I tried this:

time_restricted_data = Data[ (Data['time'] > 0.6) & (Data['time'] < 0.7) ]

But that returned all the data where Data['time'] > 0.6.

Any suggestions?

4

1 回答 1

1

Something is wrong in your example, i.e. I can't confirm it, and I think what you wrote should work as expected:

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)]
于 2012-05-01T15:29:43.133 回答