![](https://img-blog.csdn.net/2018070513111292?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3N5c3VfQWxleA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
![](https://img-blog.csdn.net/20180705131118909?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3N5c3VfQWxleA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
#10.1
import numpy as np
import scipy.optimize as opt
m = 20
n = 10
A = np.random.normal(loc=10, scale=3 , size=(m,n))
b = np.random.normal(size=m)
ans = opt.lsq_linear(A, b)
x = ans['x']
residual = b - np.dot(A,x)
print(np.linalg.norm(residual))
#10.2
import numpy as np
import scipy.optimize as opt
# f(x) = sin 2(x − 2)e −x 2
def f(x):
return -1 * np.power(np.sin(x-2), 2) * np.exp(-1*(x**2))
#the maximum of the function
res = opt.minimize_scalar(f)
x = res.x
print(-1*f(x))
#10.3
import numpy as np
import scipy.spatial.distance as distance
n = 20
m = 10
X = np.random.normal(loc = 10 , scale = 4 , size = (n, m))
ans = distance.pdist(X)
print(ans)