How to fill matrix center diagonal with different values using numpy in Python

1 Answer

0 votes
import numpy as np

matrix = np.arange(9).reshape((3,3))

np.fill_diagonal(matrix, [162, 371, 910])

print(matrix)



'''
run:

[[162   1   2]
 [  3 371   5]
 [  6   7 910]]

'''

 



answered Nov 17, 2022 by avibootz

Related questions

...