How can I create anti-diagonal matrix in numpy? I can surely do it manually, but curious if there is a function for it.
I am looking for a Matrix with the ones going from the bottom left to the upper right and zeros everywhere else.
Use np.eye(n)[::-1]
which will produce:
array([[ 0., 0., 0., 0., 1.],
[ 0., 0., 0., 1., 0.],
[ 0., 0., 1., 0., 0.],
[ 0., 1., 0., 0., 0.],
[ 1., 0., 0., 0., 0.]])
for n=5
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