Say I have an 2d numpy array like this
[[1,2,3],
[4,5,6],
[7,8,9]]
I then want to convert it to
[[3,4],
[9,10],
[15,16]]
This could be a variable number of columns, I want to add the first column to every other column and remove it as well afterwards.
>Solution :
a = a[..., [0]] + a[..., 1:]
The …is for this to work with N dimensional arrays
Means -> Sum the [0] column to all the columns after the first one.
If you are using just a matrix you can use:
a = a[:, [0]] + a[:, 1:]