Brief introduction:
The SCIPY package contains various toolkits dedicated to common problems in scientific computing. Its different sub-modules correspond to different applications. Like interpolation, integration, optimization, image processing, special functions and so on.
SciPy can be compared with other standard scientific computing libraries, such as the GSL (GNU C or C + + Scientific Computing Library), or the MATLAB toolbox. SCIPY is the core package of the scientific computing program in Python, which is used to efficiently compute the numpy matrix to allow NumPy and scipy to work together.
Before implementing a program, it is worthwhile to check whether the required data processing method has already existed in scipy. As a non-professional programmer, scientists always like to reinvent the wheel, leading to loopholes, optimizations, and hard-to-share and maintainable code. Instead, the SCIPY program is optimized and tested so that it should be used whenever possible.
module:
SCIPY consists of a number of sub-modules with specific functions:
Module |
function |
Scipy.cluster |
Vector quantization/k-means |
Scipy.constants |
Physical and mathematical constants |
Scipy.fftpack |
Fourier transform |
Scipy.integrate |
Integration Program |
Scipy.interpolate |
Interpolated values |
Scipy.io |
Data input and output |
Scipy.linalg |
Linear algebra Program |
Scipy.ndimage |
n-dimensional image package |
Scipy.odr |
Orthogonal distance regression |
Scipy.optimize |
Optimization |
Scipy.signal |
Signal Processing |
Scipy.sparse |
Sparse matrices |
Scipy.spatial |
Spatial data structures and algorithms |
Scipy.special |
Any special mathematical function |
Scipy.stats |
Statistics |
They all depend on numpy, but each is fundamentally independent. The standard way to import NumPy and these scipy modules is to:
1 Import NumPy as NP 2 from Import stats #
The main scipy namespaces mostly contain real numpy functions (try Scipy.cos is Np.cos). These are only for historical reasons and there is usually no reason to use import scipy in your code.
Note: The import scipy as SP after sp. submodule fails, so the from import method above is recommended.
Describes several functions:
Because the SCIPY package is too complete and complex, and temporarily it seems that my needs are not particularly urgent, so simple introduction of a few I feel quite interesting function part, later in the Sklearn machine learning will continue to deal with, so, SP, Next also please more advice.
Import integration packs, interpolation packages
1 Import NumPy as NP 2 Import Matplotlib.pyplot as Plt 3 from Import Integrate,interpolate
Integral:
One-dimensional integration attempts:
Integrate.quad (Lambda x:np.exp (-x**2), -10,10): original function, lower bound, upper limit
1 " " Numerical Integration " " 2 3 # Special Package Sciyp.intergrate 4 5 Print (Integrate.quad (Lambda x:np.exp (-x**2), -10,10))
Two-dimensional integration:
1 defhalf_circle (x):2 return(1-x**2) **0.53 defhalf_sphere (x, y):4 return(1-x**2-y**2) **0.55res = Integrate.dblquad (Half_sphere,-1, 1,#original function, x lower limit, y lower limit6 LambdaX:-half_circle (x),#y integral area lower limit7 LambdaX:half_circle (x))#y-Integral area cap8 Print(Res[0])
Try drawing a Picture:
1 ImportMatplotlib.pyplot as Plt2 fromMpl_toolkits.mplot3dImportAxes3d3U = np.linspace ( -1,1,100)4X, y = Np.meshgrid (u,u)#grid coordinate generation function5z = Np.abs ((1-x**2-y**2)) **0.56Fig =plt.figure ()7Ax =axes3d (Fig)8Ax.plot_surface (x,y,z,rstride=4,cstride=4,cmap='Rainbow')9Plt.show ()
Interpolated values:
INTERPOLATE.INTERP1D (x,signal)
interpolate.interp1d (x,signal,kind= ' cubic ')
1 " "interpolated Values" "2 3 #Create a signal4x = Np.linspace ( -18,18,36)5Noise = 0.1*Np.random.random (len (x))6Signal = Np.sinc (x) +Noise7 8 #generating the interpolation function once9interpreted = interpolate.interp1d (x,signal)#<---------Tenx2 = Np.linspace ( -18,18,180) Oney =interpreted (x2) A - #generate three-time interpolation functions -Cubic = interpolate.interp1d (x,signal,kind='Cubic')#<--------- they2 =Cubic (x2) - -Plt.plot (x,signal,marker='o', label='Data') -Plt.plot (x2,y,linestyle='-', label='Linear') +Plt.plot (X2,y2,'-', lw=2,label='Cubic') - plt.legend () +Plt.show ()
Summary:
For this book ("NumPy Study Guide") learning to this is over, because NumPy for the special status of Python, for her familiarity with the learning process will inevitably accompany my remaining life is quite a long part, so there is no sadness, but the new pit is ready, ready to continue to do a great job. In 21 times, in this version of the World of Warcraft past a Transition End series: The burning expedition will continue, and we will march on the Ashes!
"Python" NumPy Learning Guide Tenth-high-end Scientific Computing Library SCIPY Introduction (end of series)