Hi i have this matrix
e.g
import numpy as np
a= np.arange(9).reshape(3, 3)
[[1. 2. 3. ]
[4. 5. 6. ]
[7. 8. 9. ]]
how do i delete the bottomost value of a selected col (e.g col = 1) and the rest of the values on top gets pushed down, and if there is an empty space, put "0"
so the matrix becomes
[[1. 0. 3. ]
[4. 2. 6. ]
[7. 5. 9. ]]
Roll the second column and then set the first element of the column to zero
a = np.arange(1,10).reshape(3, 3)
a[:, 1] = np.roll(a[:, 1], 1)
a[0, 1] = 0
print(a)
Output:
[[1 0 3]
[4 2 6]
[7 5 9]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With