简体   繁体   English

如何基于另一个数组删除或屏蔽numpy数组中的值

[英]How to remove or mask values in a numpy array based on another array

I have two numpy arrays xVal and yVal . 我有两个numpy数组xValyVal 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的范围信息调整大小或屏蔽yValxVal ,因此我可以绘制xValyVal

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.deletexValyVal删除索引值

xVal2 = np.delete(xVal, indexRemove)
yVal2 = np.delete(yVal, indexRemove)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM