Numpy
Numpy
NumPy Methods
NumPy provides a wide range of methods for performing various operations on arrays.
Here are some examples:
1. Basic Operations:
np.sum(): Calculate the sum of an array.
np.mean(): Calculate the mean of an array.
np.median() : Calculate the median of an array.
np.std(): Calculate the standard deviation of an array.
2. Indexing and Slicing:
my_array[0] : Access the first element of the array.
my_array[1:3] : Access the second and third elements of the array.
my_array[:, 1]: Access the second column of a 2D array.
3. Array Manipulation:
np.concatenate(): Concatenate two or more arrays.
np.reshape(): Reshape an array to a new shape.
np.transpose(): Transpose an array (swap rows and columns).
4. Mathematical Operations:
np.dot(): Perform matrix multiplication.
np.linalg.inv() : Calculate the inverse of a matrix.
np.linalg.det() : Calculate the determinant of a matrix.
Here is a comprehensive NumPy cheat sheet with many of its methods, along
with examples and explanations. This file covers various aspects of NumPy,
including array creation, basic operations, indexing and slicing, array
manipulation, mathematical operations, random number generation, and
more.
Array Creation
numpy.array(): Create a NumPy array from a Python list or tuple.
python
python
python
python
python
python
python
Basic Operations
numpy.sum(): Calculate the sum of an array.
python
python
python
python
python
python
python
python
VerifyOpen In EditorEditCopy code
1my_array = np.array([[1, 2], [3, 4], [5, 6]])
2result = my_array[:, 1] # [2, 4, 6]
my_array[1:, 1:]: Access the second row and second column of a 2D
array.
python
Array Manipulation
numpy.concatenate(): Concatenate two