import numpy as np
mat1 = np.mat("1 2 3 ; 4 5 6 ; 7 8 9")
print(mat1)
[[1 2 3]
[4 5 6]
[7 8 9]]
type(mat1)
numpy.matrix
mat2 = np.matrix([[1,2,3],[4,5,6],[7,8,9]])
print(mat2)
[[1 2 3]
[4 5 6]
[7 8 9]]
type(mat2)
numpy.matrix
arr1 = np.eye(3)
arr2 = 3 * arr1
print(arr1)
print(arr2)
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
[[3. 0. 0.]
[0. 3. 0.]
[0. 0. 3.]]
mat = np.bmat("arr1 arr2 ; arr1 arr2")
print(mat)
[[1. 0. 0. 3. 0. 0.]
[0. 1. 0. 0. 3. 0.]
[0. 0. 1. 0. 0. 3.]
[1. 0. 0. 3. 0. 0.]
[0. 1. 0. 0. 3. 0.]
[0. 0. 1. 0. 0. 3.]]
m1 = np.matrix(np.arange(4).reshape(2,2))
print(m1)
[[0 1]
[2 3]]
mT = m1.T
mH = m1.H
mI = m1.I
print(mT)
print(mH)
print(mI)
[[0 2]
[1 3]]
[[0 2]
[1 3]]
[[-1.5 0.5]
[ 1. 0. ]]
m2 = mat1 * 3
m3 = mat1 + mat2
m4 = mat1 - mat2
m5 = mat1 * mat2
m6 = np.multiply(mat1,mat2)
print(m2)
[[ 3 6 9]
[12 15 18]
[21 24 27]]
print(m3)
print(m4)
[[ 2 4 6]
[ 8 10 12]
[14 16 18]]
[[0 0 0]
[0 0 0]
[0 0 0]]
print(m5)
print(m6)
[[ 30 36 42]
[ 66 81 96]
[102 126 150]]
[[ 1 4 9]
[16 25 36]
[49 64 81]]
mi = m1 * mI
print(mi)
[[1. 0.]
[0. 1.]]
m7 = mat1 ** 2
print(m7)
[[ 30 36 42]
[ 66 81 96]
[102 126 150]]
inverse = np.linalg.inv(m1)
print(inverse)
[[-1.5 0.5]
[ 1. 0. ]]
A = np.dot(m1,inverse)
print(A)
[[1. 0.]
[0. 1.]]
A1 = np.mat("1,-1,1 ; 2,1,0 ; 2,1,-1")
print(A1)
[[ 1 -1 1]
[ 2 1 0]
[ 2 1 -1]]
b = np.array([4,3,-1])
x = np.linalg.solve(A1,b)
print(x)
[1. 1. 4.]
A2 = np.matrix([[1,0,2],[0,3,0],[2,0,1]])
t1 = np.linalg.eig(A2)
print(t1)
(array([ 3., -1., 3.]), matrix([[ 0.70710678, -0.70710678, 0. ],
[ 0. , 0. , 1. ],
[ 0.70710678, 0.70710678, 0. ]]))
A3 = np.mat("4.0,11.0,14.0 ; 8.0,7.0,-2.0")
qyz = np.linalg.svd(A3,full_matrices = False)
print(qyz)
(matrix([[ 0.9486833 , -0.31622777],
[ 0.31622777, 0.9486833 ]]), array([18.97366596, 9.48683298]), matrix([[ 0.33333333, 0.66666667, 0.66666667],
[ 0.66666667, 0.33333333, -0.66666667]]))
A4 = np.mat("3,4 ; 5,6")
ah = np.linalg.det(A4)
print(ah)
-2.0000000000000004
|