我有一组浮标。我想根据多个条件选择它的值:
import numpy as np
stamps = np.linspace(1., 100., 1e3)
selected_stamps = stamps[((stamps > 2.)& (stamps < 10) & (stamps > 20.)& (stamps < 31) & (stamps > 80.)& (stamps < 95) )] # select only values within 2-10, 20-31, 80-95
我该怎么做?
发布于 2020-04-23 19:12:50
如果您像以前一样只使用and
运算符,您将得到一个空集合。您有3个范围,因此在每个范围之间需要一个or
操作符:
selected_stamps = stamps[(
((stamps > 2.) & (stamps < 10)) |
((stamps > 20.)& (stamps < 31)) |
((stamps > 80.)& (stamps < 95)) )]
https://stackoverflow.com/questions/61395074
复制相似问题