用另一个numpy数组索引numpy数组 [英] Indexing numpy array with another numpy array
本文介绍了用另一个numpy数组索引numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有
a = array([[1, 2],
[3, 4]])
和
b = array([1,1])
我想在索引a中使用b,即做a [b]并得到4而不是[[3,4],[3,4]]
我可能会做
a[tuple(b)]
有更好的方法吗?
谢谢
解决方案
根据numpy教程:
a[tuple(b)]
是执行此操作的正确方法:
http://www.scipy.org/Tentative_NumPy_Tutorial#head-3f4d28139e045> /p> Suppose I have and I'd like to use b in index a, that is to do a[b] and get 4 instead of [[3, 4], [3, 4]] I can probably do Is there a better way of doing it? Thanks According the numpy tutorial: is the correct way to do this: http://www.scipy.org/Tentative_NumPy_Tutorial#head-3f4d28139e045a442f78c5218c379af64c2c8c9e 这篇关于用另一个numpy数组索引numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!a = array([[1, 2],
[3, 4]])
b = array([1,1])
a[tuple(b)]
解决方案 a[tuple(b)]
查看全文