3段极简代码带你入门Python科学计算库SciPy
大数据DT
共 2231字,需浏览 5分钟
·
2021-03-16 21:18
导读:SciPy是基于NumPy的,提供了更多的科学计算功能,比如线性代数、优化、积分、插值、信号处理等。
from scipy import io as spio
import numpy as np
a=np.arange(10)
spio.savemat('a.mat',{'a':a})
data = spio.loadmat('a.mat', struct_as_record=True)
data['a']
array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
from scipy import linalg
m=np.array([[1,2],[3,4]])
linalg.det(m)
-2.0
import numpy as np
from scipy import optimize
import matplotlib.pyplot as plt
def f(x):
return x**2+20*np.sin(x)
x=np.arange(-10,10,0.1)
plt.plot(x,f(x))
grid=(-10,10,0.1)
x_min=optimize.brute(f,(grid,))
x_min
Out:
array([-1.42754883])
评论