To illustrate some of the similarities and differences between the linear algebra features of Sage and NumPy, we'll repeat an earlier example in which we computed the singular value decomposition of a matrix:
import numpy as np print "Two ways of creating a Numpy matrix:" A = np.matrix('1 1; 1 1; 0 0') # Matlab syntax print(A) A2 = np.matrix([[1,1], [1,1], [0,0]]) print(A2) print("Singular value decomposition:") U, s, Vstar = np.linalg.svd(A, full_matrices=False) print("U:") print(U) print("s:") print(s) print("Transpose of conjugate of V:") print(Vstar) Sigma = np.diag(s) print("Reconstructed matrix Sigma:") print(Sigma) print(np.dot(U, np.dot(Sigma, Vstar)))
The result should look like this: