NumPy Array Functions Last Updated : 24 Jan, 2025 Comments Improve Suggest changes Like Article Like Report 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.Table of ContentArray Creation FunctionsArray Manipulation FunctionsMathematical and Statistical FunctionsIndexing and Slicing FunctionsSorting and Searching FunctionsInput/Output FunctionsDifferent Methods in NumPy ArrayThis 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. Python import numpy as np arr = np.array([1, 2, 3]) print(arr) np.zeros(): Creates an array filled with zeros. Python import numpy as np zeros_array = np.zeros((2, 3)) print(zeros_array) np.ones(): Creates an array filled with ones. Python import numpy as np ones_array = np.ones((3, 2)) print(ones_array) np.arange(): Generates an array with values in a specified range. Python import numpy as np range_array = np.arange(0, 10, 2) print(range_array) np.linspace() : Generates an array of evenly spaced numbers over a specified range. Python import numpy as np linear_array = np.linspace(0, 1, 5) print(linear_array) np.random Functions: Generates arrays with random values. Python import numpy as np random_array = np.random.rand(2, 3) print(random_array) Array Manipulation Functionsnp.reshape(): Reshapes an array without changing its data. Python import numpy as np reshaped = np.reshape(np.arange(6), (2, 3)) print(reshaped) np.flatten(): Flattens a multi-dimensional array into one dimension. Python import numpy as np flattened = reshaped.flatten() print(flattened) np.transpose(): Transposes the dimensions of an array. Python import numpy as np transposed = reshaped.T print(transposed) np.concatenate(): Joins two or more arrays along an axis. Python import numpy as np a = np.array([1, 2]) b = np.array([3, 4]) concatenated = np.concatenate((a, b)) print(concatenated) Mathematical and Statistical Functionsnp.sum() : Computes the sum of array elements. Python import numpy as np array = np.array([1, 2, 3]) total = np.sum(array) print(total) np.mean(): Computes the mean of array elements. Python import numpy as np mean_value = np.mean(array) print(mean_value) np.max() and np.min(): Find the maximum and minimum values in an array. Python import numpy as np max_val = np.max(array) min_val = np.min(array) print(max_val) print(min_value) np.sqrt(): Computes the square root of each element in an array. Python import numpy as np sqrt_array = np.sqrt(array) print(sqrt_array) Indexing and Slicing FunctionsIndexing: Access specific elements Python import numpy as np array = np.array([1, 2, 3, 4]) element = array[2] print(element) Slicing: Access subsets of arrays Python import numpy as np subset = array[1:3] print(subset) Sorting and Searching Functionsnp.sort(): Sorts an array. Python import numpy as np sorted_array = np.sort(np.array([3, 1, 2])) print(sorted_array) np.argsort() : Returns the indices of the sorted elements. Python import numpy as np indices = np.argsort(np.array([3, 1, 2])) print(indices) np.where(): Returns the indices of elements that satisfy a condition. Python import numpy as np array = np.array([1, 2, 3, 4]) indices = np.where(array > 2) print(indices) Input/Output Functionsnp.save() and np.load(): Save and load arrays in binary format. Python import numpy as np np.save('array.npy', array) loaded_array = np.load('array.npy') print(loaded array) np.savetxt() and np.loadtxt() : Save and load arrays in text format. Python import numpy as np np.savetxt('array.txt', array) loaded_array = np.loadtxt('array.txt') print(loaded_array) Other Different Methods of NumPy Arrayall()diag()hypot()ones_like()any()diagflat()absolute()full_like()take()diag_indices()ceil()sin()put()asmatrix()floor()cos()apply_along_axis()bmat()degrees()tan()apply_over_axes()eye()radians()sinh()argmin()roll()npv()cosh()argmax()identity()fv()tanh()nanargmin()arange()pv()arcsin()nanargmax()place()power()arccos()amax()extract()float_power()exp()amin()compress()log()exp2()insert()rot90()log1()fix()delete()tile()log2()logical_or()append()reshape()log10()logical_and()around()ravel()dot()logical_not()flip()isinf()vdot()logical_xor()fliplr()isrealobj()trunc()array_equal()flipud()isscalar()divide()array_equiv()triu()isneginf()floor_divide()arctan2()tril()isposinf()true_divide()equal()tri()iscomplex()random.rand()not_equal()empty()isnan()random.randn()less()empty_like()iscomplexobj()ndarray.flat()less_equal()zeros()isreal()expm1()greater()zeros_like()isfinite()bincount()greater_equal()ones()isfortran()rint()prod()arctan()cbrt()square() Comment More infoAdvertise with us Next Article NumPy Array Functions anushka_jain_gfg Follow Improve Article Tags : Numpy Python-numpy Similar Reads Numpy - Array Creation Numpy Arrays are grid-like structures similar to lists in Python but optimized for numerical operations. The most straightforward way to create a NumPy array is by converting a regular Python list into an array using the np.array() function.Let's understand this with the help of an example:Pythonimp 5 min read Numpy Array Indexing Array indexing in NumPy refers to the method of accessing specific elements or subsets of data within an array. This feature allows us to retrieve, modify and manipulate data at specific positions or ranges helps in making it easier to work with large datasets. In this article, weâll see the differe 5 min read How to Map a Function Over NumPy Array? Mapping a function over a NumPy array means applying a specific operation to each element individually. This lets you transform all elements of the array efficiently without writing explicit loops. For example, if you want to add 2 to every element in an array [1, 2, 3, 4, 5], the result will be [3, 2 min read NumPy Introduction NumPy(Numerical Python) is a fundamental library for Python numerical computing. It provides efficient multi-dimensional array objects and various mathematical functions for handling large datasets making it a critical tool for professionals in fields that require heavy computation.Table of ContentK 7 min read NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read numpy.fromiter() function â Python NumPy's fromiter() function is a handy tool for creating a NumPy array from an iterable object. This iterable can be any Python object that provides elements one at a time. The function is especially useful when you need to convert data from a custom data source, like a file or generator, into a Num 2 min read Basics of NumPy Arrays NumPy stands for Numerical Python and is used for handling large, multi-dimensional arrays and matrices. Unlike Python's built-in lists NumPy arrays provide efficient storage and faster processing for numerical and scientific computations. It offers functions for linear algebra and random number gen 4 min read Numpy - ndarray ndarray is a short form for N-dimensional array which is a important component of NumPy. Itâs allows us to store and manipulate large amounts of data efficiently. All elements in an ndarray must be of same type making it a homogeneous array. This structure supports multiple dimensions which makes it 3 min read Numpy str_len() function numpy.char.str_len(arr) function is used for doing string operations in numpy. It returns the length of every string element wise. Parameters: arr : array_like of str or unicode.Input array. Returns : [ndarray] Output Array of integer. Code #1 : Python3 # Python program explaining # numpy.char.str_l 1 min read numpy.asarray() in Python numpy.asarray()function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of lists and arrays. Syntax : numpy.asarray(arr, dtype=None, order=None) Parameters : arr : [array_like] Input data, in any form that can be converted to a 2 min read Like