Podcast
Questions and Answers
Comment installer la bibliothèque NumPy?
Comment installer la bibliothèque NumPy?
Vous pouvez installer NumPy en utilisant la commande pip install numpy
.
Quel est le principal type d'objet fourni par NumPy?
Quel est le principal type d'objet fourni par NumPy?
Le principal type d'objet fourni par NumPy est l'objet ndarray
.
Comment importer la bibliothèque NumPy dans votre code?
Comment importer la bibliothèque NumPy dans votre code?
Pour importer NumPy, utilisez import numpy as np
.
Quelle commande permet de créer un tableau 2D rempli de zéros?
Quelle commande permet de créer un tableau 2D rempli de zéros?
Que représente la propriété 'shape' d'un tableau NumPy?
Que représente la propriété 'shape' d'un tableau NumPy?
Comment accéder à un élément spécifique d'un tableau 2D en NumPy?
Comment accéder à un élément spécifique d'un tableau 2D en NumPy?
Quelle fonction utilise-t-on pour créer une matrice identité en NumPy?
Quelle fonction utilise-t-on pour créer une matrice identité en NumPy?
Quel type de valeurs un tableau créé avec np.random.rand(3, 2)
contiendra-t-il?
Quel type de valeurs un tableau créé avec np.random.rand(3, 2)
contiendra-t-il?
Qu'est-ce que le slicing dans NumPy et comment l'appliquer sur un tableau 2D?
Qu'est-ce que le slicing dans NumPy et comment l'appliquer sur un tableau 2D?
Comment créer et utiliser un masque booléen dans NumPy?
Comment créer et utiliser un masque booléen dans NumPy?
Décrivez comment effectuer des opérations élément par élément sur un tableau NumPy.
Décrivez comment effectuer des opérations élément par élément sur un tableau NumPy.
Quelle est la méthode pour concaténer deux tableaux horizontalement dans NumPy?
Quelle est la méthode pour concaténer deux tableaux horizontalement dans NumPy?
Expliquez la fonction reshape
dans NumPy.
Expliquez la fonction reshape
dans NumPy.
Comment calculer le produit matriciel de deux matrices dans NumPy?
Comment calculer le produit matriciel de deux matrices dans NumPy?
Comment obtenir l'inverse d'une matrice en utilisant NumPy?
Comment obtenir l'inverse d'une matrice en utilisant NumPy?
Qu'est-ce que les fonctions universelles (ufunc) dans NumPy et donnez un exemple?
Qu'est-ce que les fonctions universelles (ufunc) dans NumPy et donnez un exemple?
Flashcards
Slicing
Slicing
Extraire une partie d'un tableau en utilisant des indices.
Masquage booléen
Masquage booléen
Crée un masque booléen en comparant les éléments d'un tableau avec une condition. Permet de filtrer les éléments qui répondent à une condition.
Opérations élémentaires
Opérations élémentaires
Permet d'effectuer des opérations mathématiques élément par élément sur un tableau. Exemples: addition, multiplication, puissance.
Concatenation
Concatenation
Signup and view all the flashcards
Redimensionnement
Redimensionnement
Signup and view all the flashcards
Transposition
Transposition
Signup and view all the flashcards
Algèbre linéaire
Algèbre linéaire
Signup and view all the flashcards
numpy.linalg
numpy.linalg
Signup and view all the flashcards
Qu'est-ce que NumPy ?
Qu'est-ce que NumPy ?
Signup and view all the flashcards
Comment importer NumPy ?
Comment importer NumPy ?
Signup and view all the flashcards
Qu'est-ce qu'un ndarray ?
Qu'est-ce qu'un ndarray ?
Signup and view all the flashcards
Comment créer un ndarray à partir d'une liste ?
Comment créer un ndarray à partir d'une liste ?
Signup and view all the flashcards
Comment créer des tableaux spécifiques avec NumPy ?
Comment créer des tableaux spécifiques avec NumPy ?
Signup and view all the flashcards
Comment déterminer la forme d'un ndarray ?
Comment déterminer la forme d'un ndarray ?
Signup and view all the flashcards
Comment connaître le nombre d'éléments dans un ndarray ?
Comment connaître le nombre d'éléments dans un ndarray ?
Signup and view all the flashcards
Comment identifier le type de données d'un ndarray ?
Comment identifier le type de données d'un ndarray ?
Signup and view all the flashcards
Study Notes
NumPy Installation and Introduction
- NumPy is installed using
pip install numpy
- NumPy is a numerical Python library
- It provides a powerful
ndarray
object (n-dimensional array) ndarray
is more efficient than Python lists, especially for large datasets and numerical operations.
Importing NumPy
- Import using
import numpy as np
Basic NumPy Array (ndarray)
ndarray
is a homogenous n-dimensional array- All elements are of the same data type (typically numbers)
- Unlike Python lists,
ndarrays
are more efficient for numerical computation.
Creating NumPy Arrays
- From Python Lists:
- 1D array:
array_1d = np.array([1, 2, 3, 4])
- 2D array:
array_2d = np.array([[1, 2, 3], [4, 5, 6]])
- 1D array:
- Using NumPy functions:
- Array of zeros:
zeros_array = np.zeros((3, 4))
(3x4 array filled with zeros) - Array of ones:
ones_array = np.ones((2, 3))
(2x3 array filled with ones) - Array with a constant value:
full_array = np.full((2, 2), 7)
(2x2 array filled with 7) - Identity matrix:
identity_matrix = np.eye(4)
(4x4 identity matrix) - Empty array:
empty_array = np.empty((3, 2))
(3x2 array filled with arbitrary initial values)
- Array of zeros:
Array Properties
- Shape:
array_2d.shape
(e.g., (2, 3)) gives the dimensions. - Size:
array_2d.size
(e.g., 6) provides the total number of elements. - Data type:
array_1d.dtype
(e.g., dtype('int64')) specifies the data type of elements. - Number of dimensions:
array_2d.ndim
(e.g., 2) indicates the array's dimensionality.
Indexing and Slicing
- Simple indexing:
element = array_2d[0, 1]
(access element at row 0, column 1) - Slicing:
sub_array = array_2d[0, :2]
(extract a portion of the array) - Boolean masking:
mask = array_1d > 2
creates a boolean mask andfiltered_array = array_1d[mask]
extracts elements satisfying the condition.
Basic Operations
- Element-wise operations:
- Addition:
result = array + 2
- Multiplication:
result = array * 2
- Exponentiation:
result = array ** 2
- Addition:
- Operations on arrays:
- Element-wise addition using
+
(e.g.,a + b
) - NumPy universal functions (ufuncs) for operations like sqrt(), sum(), mean(), etc.
- Dot products and matrix multiplication with
np.dot()
- Element-wise addition using
Reshaping & Concatenation
- Reshaping:
reshaped = array_2d.reshape((3, 2))
- Horizontal Stacking:
np.hstack((a, b))
- Vertical Stacking:
np.vstack((a, b))
Linear Algebra Operations
- Matrix Multiplication:
np.dot(A, B)
- Determinant:
np.linalg.det(A)
- Inverse:
np.linalg.inv(A)
- Eigenvalues and Eigenvectors:
np.linalg.eig(A)
Handling Errors and Missing Values
- NaN (Not a Number) and Inf (Infinity) handling
- Ignoring NaN values during calculation (e.g.,
np.nanmean()
)
NumPy vs Lists
- NumPy is faster
- NumPy uses less memory
- NumPy supports vectorized operations (efficient array operations)
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.