python - 从头到尾的 Numpy 切片

标签 python numpy

array = numpy.array([1,2,3,4,5,6,7,8,9,10])
array[-1:3:1]
>> []

我希望这个数组索引返回这样的东西:

[10,1,2,3]

最佳答案

使用np.roll到:

Roll array elements along a given axis. Elements that roll beyond the last position are re-introduced at the first.

>>> np.roll(x, 1)[:4]
array([10,  1,  2,  3])

关于python - 从头到尾的 Numpy 切片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50880157/

相关文章:

python - 如何检查字符串是否只包含 UTF-8 字符

python - 将行追加到 NumPy 记录数组

python - ndimage.label() 给出 "data type not supported"错误

python - 结构化数组: Do operations on views result in scattered arrays?

python - 我能否找出一个 numpy 向量是否显示为另一个向量的切片?

python - 无法导入子模块中的包

Python——读取文件并确定最低分数和人

python - 仅基于 2 列获取唯一行

python - 对除一个轴以外的所有轴求和

Python 比较标记化列表