0% found this document useful (0 votes)
21 views2 pages

Compte Rendu Matrice Numpy

Uploaded by

Sanad Zhioua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Compte Rendu Matrice Numpy

Uploaded by

Sanad Zhioua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import numpy as np

1. Création de matrices
matrix_1 = np.arange(1, 10).reshape(3, 3)
matrix_zeros = np.zeros((4, 4))
matrix_ones = np.ones((4, 4))
identity_matrix = np.eye(5)

2. Indexation et slicing

matrix_2 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])


sub_matrix = matrix_2[1:3, 1:3]
matrix_random = np.random.random((4, 4))
first_column = matrix_random[:, 0]

3. Opérations arithmétiques sur les matrices

matrix_a = np.random.random((3, 3))


matrix_b = np.random.random((3, 3))
addition = matrix_a + matrix_b
subtraction = matrix_a - matrix_b
elementwise_multiplication = matrix_a * matrix_b
elementwise_division = matrix_a / matrix_b
matrix_multiplication = np.dot(matrix_a, matrix_b)

4. Manipulation et transformation de matrices

matrix_5x5 = np.random.random((5, 5))


max_position = np.unravel_index(np.argmax(matrix_5x5), matrix_5x5.shape)
min_position = np.unravel_index(np.argmin(matrix_5x5), matrix_5x5.shape)
matrix_1d = np.arange(12)
matrix_3x4 = matrix_1d.reshape(3, 4)

5. Statistiques sur les matrices

matrix_6x6 = np.random.random((6, 6))


mean = np.mean(matrix_6x6)
median = np.median(matrix_6x6)
std_dev = np.std(matrix_6x6)
variance = np.var(matrix_6x6)
matrix_4x4 = np.random.random((4, 4))
mean_col = np.mean(matrix_4x4, axis=0)
std_col = np.std(matrix_4x4, axis=0)
normalized_matrix = (matrix_4x4 - mean_col) / std_col

6. Algèbre linéaire avec NumPy

matrix_3x3 = np.random.randint(1, 10, (3, 3))


determinant = np.linalg.det(matrix_3x3)
matrix_symmetric = np.array([[2, -1, 0], [-1, 2, -1], [0, -1, 2]])
eig_values, eig_vectors = np.linalg.eig(matrix_symmetric)
coefficients = np.array([[3, 2, -1], [2, -2, 4], [-1, 0.5, -1]])
constants = np.array([1, -2, 0])
solution = np.linalg.solve(coefficients, constants)

7. Calcul du déterminant
matrix_4x4_random = np.random.random((4, 4))
determinant_4x4 = np.linalg.det(matrix_4x4_random)
8. Inversion de matrice

matrix_non_singular = np.random.randint(1, 10, (3, 3))


inverse_matrix = np.linalg.inv(matrix_non_singular)
identity_check = np.dot(matrix_non_singular, inverse_matrix)

9. Résolution de systèmes linéaires

coefficients_2 = np.array([[4, 3, 1], [2, -1, 5], [6, 2, 3]])


constants_2 = np.array([10, 8, 14])
solution_2 = np.linalg.solve(coefficients_2, constants_2)

You might also like