I'm trying to rotate an array in Python. I've read the following post Python Array Rotation
Where I found this little snippet of code
arr = arr[numOfRotations:]+arr[:numOfRotations]
I've tried to put this into the following function:
def solution(A, K):
A = A[K:] + A[:K]
print(A)
return A
Where A is my array and K is the number of rotations. Only I get the following error, ValueError: operands could not be broadcast together with shapes (3,) (2,).
I don't understand where I'm going wrong? Ideally I a solution that can solve this without using any Numpy inbuilt short cuts functions.
Cheers
Edit: This is the full program
A = np.array([1, 2, 3, 4, 5])
def solution(A, K):
A = A[K:]+A[:K]
print(A)
return A
solution(A, 2)