I want to perform a swap between lines in np.array in python. What I want is to take the first line of the array and put it in the end of the array. I have the code that you can swap two rows which is the following:
import numpy as np
my_array = np.arrange(25).reshape(5, 5)
print my_array, '\n'
def swap_rows(arr, frm, to):
arr[[frm, to],:] = arr[[to, frm],:]
//swap_rows(my_array, 0, 8)
//print my_array
my_array[-1] = my_array[0]
print my_array
But this code performs the swap between first and last row. I want just to put the first line in the end. How can I do so?
The initial matrix is the following:
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]]
The desired outcome is the following:
[[ 5 6 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]
[ 0 1 2 3 4]]
EDIT: I am trying to do the same in my matrix which is the following:
But it doesnt change anything. My code is the following:
initial_data.append(copy.deepcopy(tab))
initial_data2 = np.asarray(initial_data)
initial_data3 = np.roll(initial_data2, -1, axis=0)
I am getting the same array.
