Ris*_*shi 9 python select numpy recarray
我有一个Numpy rec数组,我想从中做一些类似于SQL的快速查询:SELECT * where array['phase'] == "P".我想获得一个记录数组作为输出,每行对应于满足查询条件的原始数组中的一行.有任何想法吗?我很确定我以前做过这个,但是不记得这个功能.
谢谢
rec.array([ (5295499, 2.8123965, 127.20443, 0.0, 1237680436.06, 908, -19.942589, 134.33951, 0.3888, 'P', 0.19513991),
(5295499, 2.8123965, 127.20443, 0.0, 1237680436.06, 1387, -18.102, 125.639, 0.11, 'P', 1.2515257),
(5447254, 39.025873, 143.31065, 0.0, 1245455521.85, 1512, 33.121667, 130.87833, 0.573, 'LR', 45.099504)],
dtype=[('eventid', '<i4'), ('eventlat', '<f8'), ('eventlon', '<f8'), ('eventdepth', '<f8'), ('eventtime', '<f8'), ('stationid', '<i4'), ('stationlat', '<f8'), ('stationlon', '<f8'), ('stationelv', '<f8'), ('phase', '|S7'), ('timeresidual', '<f8')])
Run Code Online (Sandbox Code Playgroud)
尝试:
array[array['phase']=='P']
Run Code Online (Sandbox Code Playgroud)
array['phase']=='P'返回一个布尔numpy数组.当idx是一个布尔阵列,array[idx]返回在其中的那些行组成的阵列idx是True.
| 归档时间: |
|
| 查看次数: |
3849 次 |
| 最近记录: |