第十三周的作业

scipy 作业
10.1 题目
这里写图片描述
(1)代码:

import numpy as np
import scipy.linalg

m = 10
n = 8
A = np.asmatrix(np.random.normal(size=(m, n)))
b = np.asmatrix(np.random.normal(size=(m, 1)))
(x, res, rnk, s) = scipy.linalg.lstsq(A, b)
print("x = \n", x)
print("the norm of the residual =", res)

(2)结果截图:
这里写图片描述

10.2 题目

这里写图片描述
(1)代码:

import numpy as np
import scipy.optimize
import math

def fun(x):
    return -(math.pow(math.sin(x - 2), 2)) * (math.exp(-x**2))

ans = -scipy.optimize.fmin(fun, 0.01, full_output=1)[1]
print("the maximum of the function is", ans)

(2)结果截图:
这里写图片描述

10.3 题目
这里写图片描述
(1)代码:

import numpy as np
import scipy.spatial.distance 

n = 10
m = 8
X = np.asmatrix(np.random.normal(size=(n, m)))
Y = scipy.spatial.distance.pdist(X)
print("the pairwire distance is\n", Y)

(2)结果截图:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/m0_37600543/article/details/80558598