positions = ['GK', 'M', 'A', 'D', 'M', 'D', 'M', 'M', 'M', 'A', 'M', 'M', 'A', 'A', 'A', 'M', 'D', 'A', 'D', 'M', 'GK', 'D', 'D', 'M', 'M', 'M', 'M', 'D', 'M', 'GK', 'D', 'GK', 'D', 'D', 'M']
heights = [191, 184, 185, 180, 181, 187, 170, 179, 183, 186, 185, 170, 187, 183, 173, 188, 183, 180, 188, 175, 193, 180, 185, 170, 183, 173, 185, 185, 168, 190, 178, 185, 185, 193, 183]
np_positions = np.array(positions)
np_heights = np.array(heights)
gk_heights = np_heights[np_positions == 'GK']
a_heights = np_heights[np_positions == 'A']
a = gk_heights[gk_heights > 190]
print(gk_heights[a < 195])
I want to cut heights items which are in range from 190 to 195 and i get mistake. What's wrong and maybe you can advice me better method to do this?
CodePudding user response:
Use:
a = gk_heights[(190 < gk_heights) & (gk_heights < 195)]
print(a)
# Output
array([191, 193])
Or with your method:
a = gk_heights[gk_heights > 190]
a = a[a < 195]
print(a)
# Output
array([191, 193])
CodePudding user response:
a = [i for i in gk_heights if i > 190 and i < 195]
print(a)