Outils logiciels pour les cours Paris II
Cours Paris II
Stages/ Thèses/ Séminaires |
Python 3
import numpy as np A = np.array([ [0.1,2,2.0,1],[0.2,3,3.0,1],[0.1,4,4.1,1] ]) B=np.cov(A) At=A.transpose() Bt=np.cov(At) print("Cov A \n",B) print("Cov B \n",Bt)
import numpy as np A = np.array([ [0.1,2,2.0,1],[0.2,3,3.0,1],[0.1,4,4.1,1] ]) B=np.cov(A) print("Cov A \n",B) print("Coeff correlation ligne 1 et ligne 2",np.corrcoef(A[:1,:],A[1:2,:]))
Si B est une matrice carrée, LA est l'objet "Linear Algebra" w, v = LA.eig(B) trouve le vecteur w des valeurs propres et la liste des vecteurs propres est la matrice v. Chaque colonne est un vecteur propre.
import numpy as np from numpy import linalg as LA A = np.array([ [0.1,2,2.0,1],[0.2,3,3.0,1],[0.1,4,4.1,1] ]) B=np.cov(A) At=A.transpose() Bt=np.cov(At) print("Cov A \n",B) print("Cov At \n",Bt) w, v = LA.eig(B) print("Eigenvalues of B",w) print("Eigenvectors of B \n",v) w1, v1 = LA.eig(Bt) print("Eigenvalues of Bt",w1) print("Eigenvectors of Bt \n",v1) #Reduction to two largest eigenvalues of Bt v1r=v1[:,:2] print("2 Eigenvectors of Bt \n",v1r) Ar=np.dot(A,v1r) print("Reduced matrix A with 2 columns \n",Ar) #Reduction to two largest eigenvalues of B vr=v[:,:2] print("2 Eigenvectors of B \n",vr) Arl=np.dot(vr.transpose(),A) print("Reduced matrix A with 2 lines \n",Arl) print("Product of reduced matrices \n",np.dot(Ar,Arl)) print("Original matrix \n",A) |