SciPy作业题

import numpy as np

A = np.random.randint(-20, 20, size = 30 * 20).reshape(30, 20)
b = np.random.randint(-20, 20, size = 30 * 1).reshape(30, 1)
x = np.dot(np.dot(np.linalg.inv(np.dot(A.T, A)), A.T), b)
print(x)
print ("The norm of the residual:", np.linalg.norm(x))

结果:

SciPy作业题_第1张图片


import numpy as np
from scipy import optimize

def func(x):
    return -np.power(np.sin(x - 2), 2) * np.exp(-np.power(x, 2))

max = -optimize.minimize_scalar(func).fun
print(max)

结果:

SciPy作业题_第2张图片

SciPy作业题_第3张图片

import numpy as np
from scipy import spatial

X = np.random.randint(-20, 20, size = 10 * 10).reshape(10, 10)
print(X)
print(spatial.distance.cdist(X, X))

结果:

SciPy作业题_第4张图片

你可能感兴趣的:(作业)