如何做到在numpy的循环移位 [英] how to do circular shift in numpy
本文介绍了如何做到在numpy的循环移位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个numpy的阵列,例如:
I have a numpy array, for example
a = np.arange(10)
我怎么可以移动的第一个 N
元素添加到数组的结束?
how can I move the first n
elements to the end of the array?
我发现这个 卷
功能,但似乎它只做相反,它移到最后的 N
元素的开始。
I found this roll
function but it seems like it only does the opposite, which shifts the last n
elements to the beginning.
推荐答案
为什么不直接卷
与负数?
>>> import numpy as np
>>> a = np.arange(10)
>>> np.roll(a,2)
array([8, 9, 0, 1, 2, 3, 4, 5, 6, 7])
>>> np.roll(a,-2)
array([2, 3, 4, 5, 6, 7, 8, 9, 0, 1])
这篇关于如何做到在numpy的循环移位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文