Exercice 19
Ecrire un programme en Python numpy sous forme de fonction qui teste le type d'une matrice et renvoie True si la matrice est carrée du type nxn et False si non.
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import numpy as np def matriceShape(A): rows, columns = A.shape if rows == columns: return True else: return False # Exemple A = np.array([[2 , 1], [1 , 3]]) B = np.array([[2 , 1], [1 , -1], [1 , 3]]) # A est carée 2x2 la sortie est: True print(matriceShape(A)) # affiche: True # B n'est pas une matrice carrée ! La sortie est: False print(matriceShape(B)) # affiche: False |
Younes Derfoufi
CRMEF OUJDA
Acheter sur Très Facile !
-
Imprimante Multifonction Canon PIXMA TS3450 : A4 WiFi Jet d'encre
€ 42,00 Acheter le produit -
Cryptographie En Python: Cours et exercices avec solutions. BTS - DUT - Licence SMI - MIP
€ 20,00 Acheter le livre -
Tenda Routeur WiFi 6 RX12 Pro, Router Tenda WiFi AX3000 Bi-Bande, 5 * 6dBi Antennes à Haut Puissance, Large Couverture,
€ 57,00 Acheter le livre
1 thought on “Solution Exercice 19: type d'une matrice avec numpy”