NumPy (Numerical Python) is a fundamental library for numerical computing in Python. It provides support for multidimensional arrays, along with a collection of mathematical functions to operate on these arrays efficiently. Here are some of the key functions and features provided by NumPy:
1. Creating Arrays:
– `numpy.array()`: Create a NumPy array from a Python list or tuple.
– `numpy.zeros()`: Create an array filled with zeros.
– `numpy.ones()`: Create an array filled with ones.
– `numpy.empty()`: Create an uninitialized array.
– `numpy.arange()`: Create an array with evenly spaced values within a specified range.
– `numpy.linspace()`: Create an array with evenly spaced values over a specified interval.
2. Array Manipulation:
– `numpy.reshape()`: Reshape an array into a specified shape.
– `numpy.concatenate()`: Concatenate arrays along a specified axis.
– `numpy.split()`: Split an array into multiple sub-arrays.
– `numpy.append()`: Append values to the end of an array.
– `numpy.delete()`: Delete elements from an array.
– `numpy.sort()`: Sort an array.
3. Mathematical Functions:
– `numpy.sum()`: Compute the sum of array elements.
– `numpy.mean()`: Compute the mean of array elements.
– `numpy.median()`: Compute the median of array elements.
– `numpy.min()`, `numpy.max()`: Compute the minimum and maximum values in an array.
– `numpy.abs()`: Compute the absolute values of array elements.
– `numpy.sqrt()`: Compute the square root of array elements.
– `numpy.exp()`: Compute the exponential of array elements.
– `numpy.log()`, `numpy.log10()`: Compute the natural logarithm and base-10 logarithm of array elements.
– `numpy.sin()`, `numpy.cos()`, `numpy.tan()`: Compute trigonometric functions of array elements.
4. Array Operations:
– Element-wise operations: Addition (`+`), subtraction (`-`), multiplication (`*`), division (`/`), exponentiation (`**`), etc.
– Dot product: `numpy.dot()`, `numpy.matmul()`
– Transpose: `numpy.transpose()`, array attribute `T`
– Broadcasting: Automatic alignment of arrays with different shapes during arithmetic operations.
5. Statistical Functions:
– `numpy.mean()`, `numpy.median()`, `numpy.var()`, `numpy.std()`: Compute mean, median, variance, and standard deviation.
– `numpy.percentile()`: Compute percentiles of array elements.
– `numpy.histogram()`: Compute the histogram of an array.
6. Linear Algebra:
– Matrix multiplication: `numpy.matmul()`, `@` operator.
– Matrix inversion: `numpy.linalg.inv()`.
– Eigenvalues and eigenvectors: `numpy.linalg.eig()`.
7. Random Number Generation:
– `numpy.random.rand()`: Generate random samples from a uniform distribution.
– `numpy.random.randn()`: Generate random samples from a standard normal distribution.
– `numpy.random.randint()`: Generate random integers within a specified range.
– `numpy.random.choice()`: Generate random samples from a given 1-D array.
These are just some of the many functions provided by NumPy for efficient numerical computing in Python. NumPy’s capabilities make it a cornerstone of many scientific and data analysis workflows.