NumPy fix() function

The numpy.fix() function is used to round the array values to the nearest integers towards zero.

  • The rounded values returned by this function are in floats.

Syntax of numpy.fix():

The syntax required to use this function is as follows:

numpy.fix(array, b = None)  


The description of the parameters of this function is as follows:

  1. array: This parameter is used to indicate the array whose elements are to be rounded.
  2. b: This parameter is used to provide an ndarray (which is optional) which represents the location into which the result will be stored.

Returned Values:

This function always returns an array containing the rounded values.

Now it’s time to cover an example.

Basic Example for numpy.fix():

Below we have the code snippet to gain the understanding of how this method works:

import numpy as np  
a = [0.289, 0.089, 1.2, 1.566, 9.909]  
print("The Input array is :")  
y = np.fix(a)  
print("The Output array is :")


The Input array is : 
[0.289, 0.089, 1.2, 1.566, 9.909] 
The Output array is : 
[0. 0. 1. 1. 9.]
Follow Us On