I have two numpy arrays xVal
and yVal
. I also have a range for xVal
say (minVal,maxVal)
. I can get the values of xVal
in the range using
xVal[(xVal>=minVal)&(xVal<=maxVal)]
or the index of values in xVal
in range as
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
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
xVal2 = np.delete(xVal, indexRemove)
yVal2 = np.delete(yVal, indexRemove)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.