【问题标题】:NumPy indexing using List?使用列表的 NumPy 索引?
【发布时间】:2016-04-15 10:58:45
【问题描述】:

特种部队,

我注意到这个 URL 中有一个有趣的 NumPy 演示:

http://cs231n.github.io/python-numpy-tutorial/

我看到了:

import numpy as np

a = np.array([[1,2], [3, 4], [5, 6]])

# An example of integer array indexing.
# The returned array will have shape (3,) and 

print( a[[0, 1, 2], [0, 1, 0]] )
# Prints "[1 4 5]"

我理解使用整数作为索引参数:

a[1,1]

这个语法:

a[0:2,:]

一般来说, 如果我使用列表作为索引语法,这是什么意思?

具体来说, 我不明白为什么:

print( a[[0, 1, 2], [0, 1, 0]] )
# Prints "[1 4 5]"

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    最后一条语句将打印(以矩阵表示法)a(0,0)a(1,1)a(2,0)。在 python 表示法中,a[0][0]a[1][1]a[2][0]

    第一个索引列表包含第一个轴的索引(矩阵表示法:行索引),第二个列表包含第二个轴的索引(列索引)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-19
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 2020-05-26
      相关资源
      最近更新 更多