更新时间:2022-04-19 22:53:50
The best way to do this is to use the ix_
function: see the answer by MSeifert for details.
或者,您可以通过x
和y
使用链式索引操作:
Alternatively, you could use chain the indexing operations using x
and y
:
>>> A[x][:,y]
array([[ 2, 4, 5],
[12, 14, 15]])
第一个x
用于选择A
的行.接下来,[:,y]
选择由y
的元素指定的子数组的列.
First x
is used to select the rows of A
. Next, [:,y]
picks out the columns of the subarray specified by the elements of y
.
在这种情况下,链接是对称的:如果愿意,还可以先使用A[:,y][x]
选择列.
The chaining is symmetric in this case: you can also choose the columns first with A[:,y][x]
if you wish.