我想索引numpy数组中的所有元素,并在末尾包括第一个索引。因此,如果我有数组
[2, 4, 6]
,我希望索引数组,使结果为[2, 4, 6, 2]
。import numpy as np
a = np.asarray([2,4,6])
# One solution is
cycle = np.append(a, a[0])
# Another solution is
cycle = a[[0, 1, 2, 0]]
# Instead of creating a list, can indexing type be combined?
cycle = a[:+0]