python作业之numpy and scipy

import numpy
from scipy import linalg
import time



A = numpy.random.normal(size=(200, 500))
B = linalg.toeplitz(list(range(0,500)))
'''
1
def ex1(A,B,X):
    I = numpy.eye(500)
    print(numpy.dot(A,B-X*I))

print(A+A)
print("\n\n")
print(numpy.dot(A,A.T))
print("\n\n")
print(numpy.dot(A.T,A))
print("\n\n")
print(numpy.dot(A,B))
print("\n\n")
ex1(A,B,3)
'''

'''
2
b = numpy.arange(500,0,-1)
x = numpy.linalg.solve(B,b)
print(x)
'''

'''
3
print(linalg.norm(A, 'fro'))
print(linalg.norm(B, numpy.inf))
b = linalg.svdvals(B)
print(max(b))
print(min(b))
'''

'''
4
def ex4(n):
    Z = numpy.random.normal(0, 1, n*n).reshape(n, n) # Z矩阵
    v = numpy.array(list(range(1, n+1))[::-1]) # 初始向量
    a, tempa = linalg.norm(v,numpy.inf), 0 # 特征值
    x = 0 # 记录次数
    t = time.clock() # 记录时间
    while True:
        tempa = a
        a = linalg.norm(y, numpy.inf)
        y = numpy.dot(Z, v)
        v = y / a
        x += 1
        if abs(tempa - a) < 0.00001:# 判停条件
            break
    t = time.clock() - t
    return x, t, v, a

result = ex4(10)
print("次数为:" + str(result[0]))
print("时间为:" + str(result[1]))
print("特征向量为:" + str(result[2]))
print("特征值为:" + str(result[3]))
'''

'''
5
def ex5(n, p):
    return max(linalg.svdvals(numpy.random.binomial(1, p, [n,n])))
print(ex5(10, 0.3))
print(ex5(100, 0.3))
print(ex5(1000, 0.3))
#越来越接近np
'''


'''
6
a = min(A[A>0.5])
b = max(A[A<=0.5])
x = b if abs(a-0.5) > abs(b-0.5) else a
print(x)
'''
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值