[英]How to remove or mask values in a numpy array based on another array
I have two numpy arrays xVal
and yVal
. 我有两个numpy数组
xVal
和yVal
。 I also have a range for xVal
say (minVal,maxVal)
. 我也有
xVal
的范围说(minVal,maxVal)
。 I can get the values of xVal
in the range using 我可以使用在范围内获得
xVal
的值
xVal[(xVal>=minVal)&(xVal<=maxVal)]
or the index of values in xVal
in range as 或者
xVal
中的值的索引范围为
np.where((xVal>=minVal)&(xVal<=maxVal))
What is a pythonic approach to resize or mask yVal
based on this range information of xVal
, so I can plot xVal
vs yVal
什么是基于
yVal
的范围信息调整大小或屏蔽yVal
的xVal
,因此我可以绘制xVal
与yVal
This is the most pythonic answer I could come up with 这是我能想到的最狡猾的答案
Get the index of values not in range as 获取不在范围内的值索引
indexRemove = np.where(np.logical_not((xVal>=minVal)&(xVal<=maxVal)))
and then use np.delete
to remove the index values from xVal
and yVal
然后使用
np.delete
从xVal
和yVal
删除索引值
xVal2 = np.delete(xVal, indexRemove)
yVal2 = np.delete(yVal, indexRemove)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.