Scipy Quickstart: Dive into Scientific Computing within Minutes
SciPy is a free and open-source Python library used for scientific computing and technical computing. SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers and other tasks common in science and engineering.
SciPy is a library that uses NumPy for more mathematical functions. SciPy uses NumPy arrays as the basic data structure, and comes with modules for various commonly used tasks in scientific programming, including linear algebra, integration (calculus), ordinary differential equation solving, and signal processing.
Does SciPy use NumPy?
SciPy builds on the NumPy array object and is part of the NumPy stack which includes tools like Matplotlib, pandas and SymPy, and an expanding set of scientific computing libraries. This NumPy stack has similar users to other applications such as MATLAB, GNU Octave, and Scilab.
Installation
pip install scipy
pip install numpy
pip install matplotlib
Lets get Started
For Info
from scipy import cluster
import scipyscipy.info(cluster) scipy.source(cluster)
Special Functions
- Exponential Functions
from scipy import special
a = special.exp10(2) # 10 pow(2)
print(a)>>100.0b = special.exp2(6)
print(b)>>64.0
2. Trignometric Functions
c = special.sindg(90)
print(c)>>1.0d = special.sindg(45)
print(d)>>0.7071067811865476d = special.cosdg(90)
print(d)>>-0.0d = special.cosdg(0)
print(d)>>1.0d = special.tandg(45)
print(d)>>1.0d = special.tandg(90)
print(d)>>inf
Integration Functions
- General Intergration
from scipy import integrate
help(integrate.quad)i = scipy.integrate.quad(lambda x: special.exp10(x),0,1)
print(i)>>(3.9086503371292665, 4.3394735994897923e-14)
2. Double intergration
e = lambda x,y: x*y**2
f = lambda x: 1
g = lambda x:-1integrate.dblquad(e,0,2,f,g)>>(-0.0, 4.405142707569776e-14)
Fourier Transformations
from scipy.fftpack import fft,ifft
import numpy as np arr = np.array([1,2,3,4,5])fft = fft(arr) #fourier transform
ifft = ifft(arr) #inverse fourier transformprint("array = " ,arr)
print("\n fourier transform = ",fft)
print("\n inverse fourier transform = ",ifft)>>array = [1 2 3 4 5]
>> fourier transform = [15. -0.j -2.5+3.4409548j -2.5+0.81229924j -2.5-0.81229924j
-2.5-3.4409548j ]
>> inverse fourier transform = [ 3. -0.j -0.5-0.68819096j -0.5-0.16245985j -0.5+0.16245985j
-0.5+0.68819096j]
Linear Algebra
from scipy import linalg
a = np.array([[5,6],[8,4]])
b = linalg.inv(a)
print(b)>>[[-0.14285714 0.21428571]
[ 0.28571429 -0.17857143]]
Interpolation Functions
import matplotlib.pyplot as plt
from scipy import interpolate
x = np.arange(5,20)
y = np.exp(x/3.0)
f = interpolate.interp1d(x,y)
x1 = np.arange(6,12)
y1 = f(x1) # use interpolation function returned by 'interp1d'
plt.plot(x,y, 'o' ,x1,y1, '--')
>> [<matplotlib.lines.Line2D at 0x18c10ccb348>,
>> <matplotlib.lines.Line2D at 0x18c10cd3508>]
More info
you can find here: https://www.scipy.org/