Exercice 17
On considère la matrice:
1 |
A = np.array([1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9]) |
Ecrire un algorithme python-numpy qui transforme le type de cette matrice en 3x3
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import numpy as np A = np.array([1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9]) # modification du type de la matrice A en 3x3 A = A.reshape(3 , 3) print(A) """ Affiche: [[1 2 3] [4 5 6] [7 8 9]] """ |
Younes Derfoufi
CRMEF OUJDA
1 thought on “Solution Exercice 17: la méthode numpy reshape()”