(Cours Python 3 [Mode de compatibilit  351] )
18 pages
Français

(Cours Python 3 [Mode de compatibilit 351] )

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
18 pages
Français
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Initiation à la programmation en PythonRomain Brette11 mars 2009Calcul scientifique: SciPy et Pylab SciPy = bibliothèque scientifique≈ Matlab Pylab = bibliothèque graphique Utilisation:fromfrom scipy import *from pylab*Documentation:http://docs.scipy.org/doc/http://matplotlib.sourceforge.net/ (voir la gallerie d’exemples)http://mathesaurus.sourceforge.net/matlab-numpy.htmlSciPPyyVecteurs et matrices Type de base défini par SciPy: array(= vecteur ou matrice)from scipy import *vecteur (1,2,3)x=array([1,2,3])M=array([[1,2,3],[4,5,6]])1 2 3matrice44 55 6M=ones((3,2)) 11 1matrice1 1z=2*x+1 1 1y=dot(M,x)produit matricielOpérationsx+yx-yx*yélément par élémentx/yx**2 x²exp(x)sqrt(x)dot(x,y)produit scalairedot(M,x)produit matricielM.TtranspositionM.max()maximumM.sum()sommesize(x)nombre total d’élémentsM.shapeIndexationIndexation des vecteurs ≈ listes (premier élément = 0)ex[i](i+1) élementM[i,j]x[i:j]tranche de x[i] à x[j-1]e(i+1) ligneM[i,:]e(i+1) colonneM[:,i]éléments x[1] et x[3]x[[1,3]]x[1:3]=[0,1]x[1]=0, x[3]=1eM[1,:]+=x ajouter le vecteur x à la 2 ligne de MM[i,:]est une « vue » sur la matrice M ≠ copie (≈ référence)y=M[0,:]y[2]=5M[0,2] vaut 5x=zcopie:x[1]=3 z[1] vaut 3x=z.copy()Constructionx=array([1,2,3])à partir de listesM=array([[1,2,3],[4,5,6]])x=ones(5)vecteur de 1M=zeros((3,2)) matrice nullematrice identitéM=eye(3)matrice diagonaleM=diag([1,3,7])vecteur aléatoire dans ...

Informations

Publié par
Nombre de lectures 103
Langue Français

Extrait

     
 
  
from
sc pylab
import *
Documentation: http://docs.scipy.org/doc/ http://matplotlib.sourceforge.net/ (voir la gallerie d’exemples) http://mathesaurus.sourceforge.net/matlab-numpy.html
M=ones(( 3 , 2 ))
z=
2 *x+1
y=dot(M,x)
matrice
1 1 1 1 1 1
produit matriciel
dot(x,y) dot(M,x)
M.T M.max() M.sum()
size(x) M.shape
produit scalaire produit matriciel
transposition maximum somme
nombre total d’éléments
x[1:3]=[0,1] M[1,:]+=x
x[1]=0, x[3]=1 ajouter le vecteur x à la 2 e ligne de M
M[i,:] est une « vue » sur la matrice M copie ( référence)
y=M[0,:] y[2]=5
x=z x[1]=3
M[0,2] vaut 5
z[1] vaut 3
copie: x=z.copy()
x=rand(5) x=randn(5)
x=arange(10)
x=linspace(0,1,100)
vecteur aléatoire dans [0,1] vecteur aléatoire gaussien
0,1,2,...,9
100 nombres entre 0 et 1
i,j=where(M>.5)
i=where(x>2.5)[0]
indices (ligne, colonne) des éléments > .5
indices des éléments > 2.5
norm lstsq solve eigvals lu ...
return (x-1)*(x-3)
print
optimize.fsolve(f,0)
point initial
résout f(x)=0
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents