整数数组索引在numpy中如何工作? [英] How does integer-array indexing work in numpy?
本文介绍了整数数组索引在numpy中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法理解numpy中的整数数组索引.
I am not able to understand integer array indexing in numpy.
>>> x = np.array([[1, 2], [3, 4], [5, 6]])
>>> x[[0, 1, 2], [0, 1, 0]]
array([1, 4, 5])
请解释一下这是怎么回事?
Please explain me what is happening in this?
推荐答案
x[[0,1,2],[0,1,0]]
[0,1,2]
<--在此指定要使用的数组 [0,1,0]
<-在这里,您可以从每个指定的数组中选择元素
[0,1,2]
<- here you specify which arrays you will be using
[0,1,0]
<- here you choose elements from each of specified arrays
所以数组0中的元素0,元素1形成了arr 1,依此类推
So element 0 from array 0, element 1 form arr 1 and so on
这篇关于整数数组索引在numpy中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文