# Python | numpy.fill_diagonal() method

With the help of `numpy.fill_diagonal()` method, we can get filled the diagonals of numpy array with the value passed as the parameter in `numpy.fill_diagonal()` method.

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 by using `numpy.fill_diagonal()` method, we are able to get the diagonals filled with the values passed as parameter.

 `# import numpy ` `import` `numpy as np ` ` `  `# using numpy.fill_diagonal() method ` `array ``=` `np.array([[``1``, ``2``], [``2``, ``1``]]) ` `np.fill_diagonal(array, ``5``) ` ` `  `print``(array) `

Output :

[[5 2]
[2 5]]

Example #2 :

 `# import numpy ` `import` `numpy as np ` ` `  `# using numpy.fill_diagonal() method ` `array ``=` `np.zeros((``3``, ``3``), ``int``) ` `np.fill_diagonal(array, ``1``) ` ` `  `print``(array) `

Output :

[[1 0 0]
[0 1 0]
[0 0 1]]

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.