Facebook Page Twitter Page LinkedIn Page
× NumPy Tutorial NumPy Resources


The NumPy has a number of built-in functions which can be used for array creation and manipulation. For example, array() function is used to create ndarray object from an array-like object. Along with this, it also contains various functions for mathematical, arithmetical and statistical operations. Below is the list of most commonly used functions of NumPy:

NumPy - Functions

Array Creation/Manipulation Functions

FunctionDescription
append() Appends values to the end of an array.
arange() Return evenly spaced values within a given interval.
array() Returns an array.
asarray() Converts the input to an array.
concatenate() Returns a concatenated array along the specified axis.
empty() Returns a new array of given shape and type, without initializing entries.
eye() Returns a 2-D array with ones on the diagonal and zeros elsewhere.
frombuffer() Interpret a buffer as a 1-dimensional array.
fromiter() Create a new 1-dimensional array from an iterable object.
histogram() Computes the histogram of a set of data.
identity() Returns the identity array.
linspace() Returns evenly spaced numbers over a specified interval.
logspace() Return numbers spaced evenly on a log scale.
ndarray.flatten() Returns a copy of the array collapsed into one dimension.
ones() Returns a new array of given shape and type, filled with ones.
ravel() Returns a contiguous flattened array.
reshape() Gives a new shape to an array without changing its data.
zeros() Returns a new array of given shape and type, filled with zeros.

Linear Algebra Functions

FunctionsDescription
linalg.det() Compute the determinant of an array.
linalg.inv() Compute the determinant of a matrix.
linalg.solve() Compute the determinant of a matrix.

Matrix Functions

FunctionsDescription
matlib.empty() Returns a matrix of given shape and type, without initializing entries.
matlib.eye() Returns a matrix with ones on the diagonal and zeros elsewhere.
matlib.identity() Returns the square identity matrix of given size.
matlib.ones() Returns a matrix of given shape and type, filled with ones.
matlib.rand() Return a matrix of random values with given shape.
matlib.randn() Return a random matrix with data from the “standard normal” distribution.
matlib.zeros() Returns a matrix of given shape and type, filled with zeros.

Statistical Functions

FunctionsDescription
average() Computes the weighted average along the specified axis.
mean() Computes the arithmetic mean along the specified axis.
median() Computes the median along the specified axis.
std() Compute the standard deviation along the specified axis.
var() Compute the variance along the specified axis.

Basic Math Functions

FunctionsDescription
argmax() Returns the indices of the maximum values along an axis.
dot() Returns dot product of two arrays.
inner() Returns inner product of two arrays.
matmul() Returns matrix product of two arrays.
sort() Returns a sorted copy of an array.
sum() Sum of array elements over a given axis.
transpose() Reverses or permutes the axes of an array.
vdot() Returns dot product of two vectors.

Trigonometric Functions

FunctionsDescription
sin() Returns the trigonometric sine of an angle in radians.
cos() Returns the trigonometric cosine of an angle in radians.
tan() Returns the trigonometric tangent of an angle in radians.
arcsin() Returns the arc sine of a value.
arccos() Returns the arc cosine of a value.
arctan() Returns the arc tangent of a value.
hypot() Given the legs of a right triangle, return its hypotenuse.
degrees() Convert angles from radians to degrees.
radians() Convert angles from degrees to radians.
rad2deg() Convert angles from radians to degrees.
deg2rad() Convert angles from degrees to radians.

Hyperbolic Functions

FunctionsDescription
sinh() Returns the hyperbolic sine of a value.
cosh() Returns the hyperbolic cosine of a value.
tanh() Returns the hyperbolic tangent of a value.
arcsinh() Returns the inverse hyperbolic sine of a value.
arccosh() Returns the inverse hyperbolic cosine of a value.
arctanh() Returns the inverse hyperbolic tangent of a value.

Rounding Functions

FunctionsDescription
around() Rounds to the given number of decimals.
ceil() Rounds the given number up to the nearest integer.
floor() Rounds the given number down to the nearest integer.
fix() Round to nearest integer towards zero.
rint() Round elements of the array to the nearest integer.
trunc() Return the truncated value of the input, element-wise.

Exponents and Logarithms Functions

FunctionsDescription
exp() Returns the exponent of e.
expm1() Returns the exponent of e minus 1, i.e., ex-1.
log() Returns the natural logarithm of a given number.
log1p() Returns the natural logarithm of (1+number), i.e., log(1+number).
log2() Returns the base-2 logarithm of a given number.
log10() Returns the base-10 logarithm of a given number.

Arithmetic Functions

FunctionsDescription
add() Add arguments element-wise.
subtract() Subtract arguments, element-wise.
multiply() Multiply arguments element-wise.
divide() Returns a true division of the inputs, element-wise.
true_divide() Returns a true division of the inputs, element-wise.
floor_divide() Return the largest integer smaller or equal to the division of the inputs.
power() Returns base raised to the power of exponent.
fmod() Return element-wise remainder of division.
mod() Return element-wise remainder of division.
remainder() Return element-wise remainder of division.
reciprocal() Return the reciprocal of the argument, element-wise.

Handling Complex Numbers

FunctionsDescription
angle() Return the angle of the complex argument.
real() Return the real part of the complex argument.
imag() Return the imaginary part of the complex argument.
conj() Return the complex conjugate, element-wise.
conjugate() Return the complex conjugate, element-wise.

Miscellaneous

FunctionsDescription
sqrt() Returns the square root of the given number.
cbrt() Returns the cube root of the given number.