Reputation: 639
If you just need to work with clasic 2D matrices, it's so fine to use numpay.mat
because of their small and intuitive atributes:
import numpy as np
x = np.mat('1 2; 3 4') # Matlab-like creating nomenclature.. cool!
y = np.mat('5 6; 7 8')
print(x.I) # inverse matrix... cool!
print(x.T) # transpose matrix... cool!
print(x*y) # matrix multiplication... cool!
print(np.linalg.det(x)) # it's so tired to have to write all this to obtain the determinant!
Is there any fancy way to aboid writting "np.linalg.det(x)" to calc a determinant?
Upvotes: 1
Views: 173
Reputation: 18306
You can assign a det
variable for shortcut because functions are first-class objects:
>>> det = np.linalg.det
>>> det(x)
-2.0000000000000004
or perhaps better with from ... import ...
:
>>> from numpy.linalg import det
>>> det(x)
-2.0000000000000004
Upvotes: 2