NumPy is a powerful numerical computing library in Python that provides support for large, multi-dimensional arrays and matrices, along with mathematical functions to operate on these arrays. Here's an overview of NumPy and some of its key functions:
1. Arrays in NumPy:
- NumPy's core is its `ndarray` (n-dimensional array) object, which is a flexible array that can be of any dimension.
- Arrays in NumPy are homogenous (all elements of the same type) and memory-efficient.
2. Key Functions:
->Creating Arrays:
- `np.array()`: Create an array from a list or tuple.
- `np.zeros()`, `np.ones()`: Create arrays of zeros or ones.
- `np.arange()`: Create an array with regularly spaced values.
- `np.linspace()`: Create an array with a specified number of elements, spaced equally between two values.
3. Array Operations:
- `np.shape`: Returns the dimensions of an array.
- `np.reshape()`: Reshape an array.
- `np.concatenate()`: Concatenate arrays.
4. Mathematical Operations:
NumPy provides a wide range of mathematical functions that operate element-wise on arrays, such as `np.add()`, `np.subtract()`, `np.multiply()`, `np.divide()`, `np.sqrt()`, `np.sin()`, `np.cos()`, etc.
5. Linear Algebra:
- `np.dot()`: Matrix multiplication.
- `np.transpose()`: Transpose of a matrix.
- `np.linalg.inv()`: Inverse of a matrix.
- `np.linalg.det()`: Determinant of a matrix.
6. Random:
- `np.random.rand()`: Generate random values in a given shape.
- `np.random.randn()`: Generate random values from a normal distribution.
- `np.random.randint()`: Generate random integers.
7. Statistical Functions:
- `np.mean()`, `np.median()`: Calculate mean and median.
- `np.std()`, `np.var()`: Calculate standard deviation and variance.
Example:
Here's a simple example that demonstrates some of these functions.
This example covers some basic concepts and functions in NumPy. NumPy's documentation is an excellent resource for more in-depth exploration: [NumPy Documentation](https://numpy.org/doc/stable/).