<jupyter_start><jupyter_text>Data Science Academy - Python Fundamentos - Capítulo 8 Download: http://github.com/dsacademybr  SciPyPara compreender o SciPy é necessário compreender conceitos avançados de Matemática e Estatística, o que está fora do escopo deste treinamento. Caso queira aprender aplicações práticas do pacote em Machine Learning e IA, consulte estes dois cursos aqui na DSA:Machine Learning: https://www.datascienceacademy.com.br/pages/curso-machine-learningProgramação Paralela em GPU: https://www.datascienceacademy.com.br/pages/curso-programacao-paralela-em-gpu  O SciPy possui um conjunto de pacotes para operações matemáticas e científicas 						Pacote			Descrição							cluster			Clustering algorithms							constants			Mathematical and physical constants							fftpack			Fourier transforms							integrate			Numerical integration							interpolate			Interpolation							io			Input and output							linalg			Linear algebra							maxentropy			Maximum entropy models							misc			Miscellaneous							ndimage			Multi-dimensional image processing							odr			Orthogonal distance regression							optimize			Optimization							signal			Signal processing							sparse			Sparse matrices							spatial			Spatial algorithms and data structures							special			Special functions							stats			Statistical functions							stsci			Image processing							weave			C/C++ integration			  Processamento de imagens<jupyter_code>from scipy import misc
misc.imread('Matplotlib-Mapa.png')    

# Matplotlib tem uma função similar
import matplotlib.pyplot as plt
plt.imread('Matplotlib-Mapa.png')<jupyter_output><empty_output><jupyter_text>Integração Numérica<jupyter_code>from numpy import *
from scipy.integrate import quad, dblquad, tplquad
# Integração
val, abserr = quad(lambda x: exp(-x ** 2),  Inf, Inf)
val, abserr
from scipy.integrate import odeint, ode
from pylab import *
%matplotlib inline
def dy(y, t, zeta, w0):
    x, p = y[0], y[1]
    
    dx = p
    dp = -2 * zeta * w0 * p - w0**2 * x

    return [dx, dp]


y0 = [1.0, 0.0]

t = linspace(0, 10, 1000)
w0 = 2*pi*1.0


y1 = odeint(dy, y0, t, args=(0.0, w0)) 
y2 = odeint(dy, y0, t, args=(0.2, w0)) 
y3 = odeint(dy, y0, t, args=(1.0, w0)) 
y4 = odeint(dy, y0, t, args=(5.0, w0)) 

fig, ax = subplots()
ax.plot(t, y1[:,0], 'k', label="Não Abafado", linewidth=0.25)
ax.plot(t, y2[:,0], 'r', label="Pouco Abafado")
ax.plot(t, y3[:,0], 'b', label="Criticamente Abafado")
ax.plot(t, y4[:,0], 'g', label="Perigosamente Abafado")
ax.legend();<jupyter_output><empty_output><jupyter_text>Fourier Transformation<jupyter_code>from scipy.fftpack import *
# Fourier transformation
N = len(t)
dt = t[1]-t[0]

F = fft(y2[:,0]) 

w = fftfreq(N, dt)

fig, ax = subplots(figsize=(9,3))
ax.plot(w, abs(F));<jupyter_output><empty_output><jupyter_text>Álgebra Linear<jupyter_code>A = array([[1,2,3], [4,5,6], [7,8,9]])
b = array([1,2,3])
# Resolvendo um sistema de equações lineares
x = solve(A, b)
x
A = rand(3,3)
B = rand(3,3)

evals, evecs = eig(A)

evals
evecs
svd(A)<jupyter_output><empty_output><jupyter_text>Otimização<jupyter_code>from scipy import optimize
def f(x):
    return 4*x**3 + (x-2)**2 + x**4

fig, ax  = subplots()
x = linspace(-5, 3, 100)
ax.plot(x, f(x));
x_min = optimize.fmin_bfgs(f, -0.5)
x_min<jupyter_output>Optimization terminated successfully.
         Current function value: 2.804988
         Iterations: 4
         Function evaluations: 18
         Gradient evaluations: 6<jupyter_text>Estatística<jupyter_code>from scipy import stats
Y = stats.norm()

x = linspace(-5,5,100)

fig, axes = subplots(3,1, sharex=True)

axes[0].plot(x, Y.pdf(x))

axes[1].plot(x, Y.cdf(x));

axes[2].hist(Y.rvs(size=1000), bins=50);
Y.mean(), Y.std(), Y.var()
# T-test
t_statistic, p_value = stats.ttest_ind(Y.rvs(size=1000), Y.rvs(size=1000))
t_statistic, p_value<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12620098675668656, 'fraction_numerical': 0.032459101532069594, 'mean_word_length': 4.129161118508655, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '600662', 'license': 'MIT', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1517, 'n_words': 366, 'path': 'Cap08/Notebooks/DSA-Python-Cap08-04-SciPy.ipynb', 'repo_name': 'CezarPoeta/Python-Fundamentos', 'size': '3851'}