Using the numpy.fill_diagonal()
method, you can fill the diagonals of a numpy array with the value passed as a parameter to numpy.fill_diagonal ()
.
Syntax:
numpy.fill_diagonal (array, value)
Return: Return the filled value in the diagonal of an array.
Example # 1:
In this example, we can see that using numpy.fill_diagonal ( )
we can get the diagonals filled with the values passed as a parameter.
|
Output:
[[5 2]
[2 5]]
Example # 2:
|
Output:
[ [1 0 0]
[0 1 0]
[0 0 1]]