使用另一个2D阵列索引NumPy 2D阵列 [英] Indexing NumPy 2D array with another 2D array

查看:175
本文介绍了使用另一个2D阵列索引NumPy 2D阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的东西

m = array([[1, 2],
            [4, 5],
            [7, 8],
            [6, 2]])

select = array([0,1,0,0])

我的目标是

result = array([1, 5, 7, 6])

我试过 _ ix 正如我在 Simplfy行和列提取,numpy ,但这并没有产生我想要的结果。

I tried _ix as I read at Simplfy row AND column extraction, numpy, but this did not result in what I wanted.

p.s。如果你能想到一个更精确的问题,请更改这个问题的标题。

p.s. Please change the title of this question if you can think of a more precise one.

推荐答案

如何使用python?

What about using python?

result = array([subarray[index] for subarray, index in zip(m, select)])

这篇关于使用另一个2D阵列索引NumPy 2D阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆