假设我有一个数值数组x = [5, 2, 3, 1, 4, 5]
,y = ['f', 'o', 'o', 'b', 'a', 'r']
。我想选择与x
中大于1和小于5的元素相对应的y
中的元素。
我试过了
x = array([5, 2, 3, 1, 4, 5])
y = array(['f','o','o','b','a','r'])
output = y[x > 1 & x < 5] # desired output is ['o','o','a']
但这不管用。我该怎么做呢?
https://stackoverflow.com/questions/3030480
复制相似问题