Numpy 高级索引

Numpy 比一般的 Python 序列索引方式。 除了之前看到的用整数和切片的索引你外, 数组可以有整数数组索引,布尔索引及花式索引。

整数数组索引

一下实例获取数组中(0, 0),(1, 1)和(2, 0)位置处的元素。

实例:
import numpy as np

x = np.numpy([[1, 2], [3, 4], [5, 6]])
y = x[[0,1,2], [0,1,1]]
print(y)

输出结果为:
[1, 4, 5]
原文地址:https://www.cnblogs.com/jcjc/p/10794978.html