版权声明:置顶文章如需转载请联系作者 https://blog.csdn.net/Bonstoppo/article/details/82796530
1.Numpy
#-*- coding:utf-8 -*-
import numpy as np
a = np.array([2 , 0 , 1 , 5])
print( a )
print(a.min())
a.sort()#sort可以记录保存数据
print(a[:3])
print(a)
b = np.array([[1 ,2 ,3] , [4 , 5 , 6]])
print(b * b)
2.Scipy
#-*- coding:utf-8 -*-
from scipy.optimize import fsolve
def f(x):
x1 = x[0]
x2 = x[1]
return [2 * x1 - x2 ** 2 - 1 , x1 ** 2 - x2 - 2]
result = fsolve(f , [1 , 1])
print(result)
from scipy import integrate
def g(x):
return (1 - x ** 2) ** 0.5
pi_2 , err = integrate.quad(g , -1 , 1)//辛普森自适应函数,在[-1 , 1]之间求g(x)的定积分//
print(err)
3.Matplotlib
#-*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0 , 10 , 1000)
y = np.sin(x) + 1
z = np.cos(x ** 2) + 1
plt.figure(figsize = (8 , 4))
plt.plot(x , y , label = '$\sin x+1$' , color = 'red' , linewidth = 2)
plt.plot(x , z , 'b--' , label = '$\cos x^2+1$' )
plt.xlabel('Time(s)')
plt.ylabel('Volt')
plt.title('A Simple Example')
plt.ylim(0 , 2.2)
plt.legend()
plt.show()