Python | sympy.diag() method
Last Updated :
29 Jun, 2019
With the help of sympy.diag()
method, we can create a matrix having dimension nxn and filled with numbers in the diagonal by using sympy.diag()
method.
Syntax : sympy.diag()
Return : Return a new matrix.
Example #1 :
In this example, we can see that by using sympy.diag()
method, we are able to create a matrix having dimension nxn all filled with numbers in a diagonal as passed in a parameter.
from sympy import *
mat = diag( 3 , 4 )
print (mat)
|
Output :
Matrix([
[3, 0],
[0, 4]])
Example #2 :
from sympy import *
mat = diag( 3 , 4 , 5 , 8 )
print (mat)
|
Output :
Matrix([
[3, 0, 0, 0],
[0, 4, 0, 0],
[0, 0, 5, 0],
[0, 0, 0, 8]])
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...