NumPy Tutorial NumPy Statistics NumPy References

NumPy - fix() function

The NumPy fix() function is used to round an array of floats element-wise to nearest integer towards zero. The rounded values are returned as floats.


numpy.fix(x, out=None)


x Required. Specify an array (array_like) of floats to be rounded.
out Optional. Specify a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.

Return Value

Returns an array containing the rounded values if out=None. If an output array is specified, a reference to out is returned.


The example below shows the usage of fix() function.

import numpy as np
Arr = np.array([[3.4,5.4],[-7.2,-15.4]])

print("Arr is:")
print(Arr )

#rounds the values to nearest 
#integer towards zero 
print("\nRounded Array (towards zero) is:")

The output of the above code will be:

Arr is:
[[  3.4   5.4]
 [ -7.2 -15.4]]

Rounded Array (towards zero) is:
[[  3.   5.]
 [ -7. -15.]]

❮ NumPy - Functions