假设我有一个numpy数组x = [5, 2, 3, 1, 4, 5]
,y = ['f', 'o', 'o', 'b', 'a', 'r']
.我想选择y
对应于x
大于1且小于5的元素的元素.
我试过了
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']
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我该怎么做?