gpt4 book ai didi

python - 从头到尾的 Numpy 切片

转载 作者:行者123 更新时间:2023-11-28 19:46:51 27 4
gpt4 key购买 nike

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com