热线电话:13121318867

登录
2019-06-17 阅读量: 574
python如何使用索引数组进行索引

使用索引数组进行索引

通过使用数组作为索引,可以在numpy中完成索引。在切片的情况下,返回数组的视图或浅副本,但在索引数组中返回原始数组的副本。Numpy数组可以使用其他数组或任何其他序列进行索引,但元组除外。最后一个元素的索引为-1秒,最后为-2,依此类推。

示例#1:

# Python program to demonstrate
# the use of index arrays.
import numpy as np

# Create a sequence of integers from
# 10 to 1 with a step of -2
a = np.arange(10, 1, -2)
print("\n A sequential array with a negative step: \n",a)

# Indexes are specified inside the np.array method.
newarr = a[np.array([3, 1, 2 ])]
print("\n Elements at these indices are:\n",newarr)

0.0000
6
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子