from scipy import linalg
import numpy as np
A = np.random.normal(0,1,100000).reshape(200,500)
B = linalg.toeplitz(list(range(1,500)))
print(A + A)
print(np.dot(A, A.T))
print(np.dot(A.T, A))
print(np.dot(A, B))
def calculate(x):
return np.dot(A, B - x * np.eye(500))
from scipy import linalg
import numpy as np
A = np.random.normal(0,1,100000).reshape(200,500)
B = linalg.toeplitz(list(range(1,501)))
b = np.linspace(1, 500, 500)
print(np.linalg.solve(B, b))
from scipy import linalg
import numpy as np
A = np.random.normal(0,1,100000).reshape(200,500)
B = linalg.toeplitz(list(range(1,501)))
#求范数和奇异值
print(linalg.norm(A, 'fro'))
print(linalg.norm(B, np.inf))
x = linalg.svdvals(B).tolist()
print(max(x))
print(min(x))
from scipy import linalg
import numpy as np
import time
A = np.random.normal(0,1,100000).reshape(200,500)
B = linalg.toeplitz(list(range(1,501)))
def Times(n):
Z = np.random.normal(0, 1, n*n).reshape(n, n)#Z矩阵
v = np.array(list(range(1, n+1))[::-1]) #初始特征向量
a = linalg.norm(v, np.inf)#特征值
temp = 0
times = 0 #次数
t = time.clock() #时间
while True:
temp = a
y = np.dot(Z, v)
a = linalg.norm(y, np.inf)
v = y / a
times = times + 1
if abs(temp - a) < 0.000001:
break
t = time.clock() - t
return times, t, v, a
n = input()
result = Times(int(n))
print("Times:%d"%result[0])
print("Time:%f"%result[1])
print("Eigenvector:",end="")
print(result[2])
print("Eigenvalue:%f"%result[3])
from scipy import linalg
import numpy as np
import time
A = np.random.normal(0,1,100000).reshape(200,500)
B = linalg.toeplitz(list(range(1,501)))
n = input()
p = input()
C = np.random.binomial(1, float(p), [int(n), int(n)])
x = linalg.svdvals(C).tolist()
print(max(x))
from scipy import linalg
import numpy as np
import time
A = np.random.normal(0,1,100000).reshape(200,500)
B = linalg.toeplitz(list(range(1,501)))
def closest(A, z):
a = min(A[A > z])#A矩阵中大于z的值的最小值
b = max(A[A <= z])#A矩阵中小于等于z的值的最小值
if abs(a - z) > abs(b - z):
return b
else:
return a
z = input()
print(closest(A, float(z)))