NumPy array functions are a set of built-in operations provided by the NumPy library that allow users to perform various tasks on arrays. With NumPy array functions, you can create, reshape, slice, sort, perform mathematical operations, and much more—all while taking advantage of the library's speed and efficiency.
This article explores some of the most important NumPy array functions with examples to help you harness their power.
Array Creation Functions
- np.array(): Converts a Python list, tuple, or sequence into an array.
- np.ones(): Creates an array filled with ones.
- np.arange(): Generates an array with values in a specified range.
- np.linspace() : Generates an array of evenly spaced numbers over a specified range.
Array Manipulation Functions
- np.flatten(): Flattens a multi-dimensional array into one dimension.
Mathematical and Statistical Functions
- np.sum() : Computes the sum of array elements.
- np.mean(): Computes the mean of array elements.
- np.sqrt(): Computes the square root of each element in an array.
Indexing and Slicing Functions
- Indexing: Access specific elements
- Slicing: Access subsets of arrays
Sorting and Searching Functions
- np.where(): Returns the indices of elements that satisfy a condition.
Input/Output Functions
- np.savetxt() and np.loadtxt() : Save and load arrays in text format.
Other Different Methods of NumPy Array