过滤1-D阵列后获取剩余向量的索引
我有两个(1维)np.array
变量:_nums
& _data
。两者都有相同的形状。
_nums
将被操纵&过滤,因此最终它的值将比_DATA
少。
>>> ls1 = [
['q1', 'q2', 'q3'],
['w1', 'w2', 'w3'],
['e1', 'e2', 'e3'],
['r1', 'r2', 'r3'],
['t1', 't2', 't3'],
['y1', 'y2', 'y3']
]
>>> _data = np.array(ls1) # This is optional.
>>> ls2 = [
[11, 22, 33],
[44, 55, 66],
[77, 88, 99],
[00, 111, 222],
[333, 444, 555],
[666, 777, 888]
]
>>> _nums = np.array(ls2, dtype=DTYPE)
>>> # _data & _nums have same shape
>>> _nums = _nums[_nums['param1'] >= X]
[[44, 55, 66], [333, 444, 555]]
所见
如您 在 ls2 中,这些值将在索引1和索引4中, _data 或 ls1 。
是否有一种数字来获取这些索引?因此,n i可以使用 _nums ...提供的索引在 _data 中提取相应的值?
I have two (1 dimensional) np.array
variables: _nums
& _data
. Both have the same shape.
_nums
is going to be manipulated & filtered so in the end it's going to have less values than _data
.
>>> ls1 = [
['q1', 'q2', 'q3'],
['w1', 'w2', 'w3'],
['e1', 'e2', 'e3'],
['r1', 'r2', 'r3'],
['t1', 't2', 't3'],
['y1', 'y2', 'y3']
]
>>> _data = np.array(ls1) # This is optional.
>>> ls2 = [
[11, 22, 33],
[44, 55, 66],
[77, 88, 99],
[00, 111, 222],
[333, 444, 555],
[666, 777, 888]
]
>>> _nums = np.array(ls2, dtype=DTYPE)
>>> # _data & _nums have same shape
>>> _nums = _nums[_nums['param1'] >= X]
[[44, 55, 66], [333, 444, 555]]
As you can see _nums shape is now different from _data or ls1...
If I manually find _nums values in ls2 those values would be at index 1 and at index 4 in _data or ls1.
Is there a numpy way to get those indexes? So the n I can extract the corresponding values in _data using the indexes provides by _nums...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 numpy broadcasting 带有
np.np.where
这样做。由于复杂性和性能的不同,许多其他选项是可能的,但是这种方法似乎很简单。You can use NumPy broadcasting with
np.where
to do this. Many other options are possible with varying complexity and performance but this method seems straightforward.