NumPy fix() function
In this tutorial, we will cover the
numpy.fix() function of the Numpy Library.
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.
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:
array: This parameter is used to indicate the array whose elements are to be rounded.
b: This parameter is used to provide an ndarray (which is optional) which represents the location into which the result will be stored.
This function always returns an array containing the rounded values.
Now it's time to cover an example.
Basic Example for
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.]
In this tutorial we covered the
numpy.fix() mathematical function of the Numpy library which can be used to round off the values in an array. If we want to round only some values, then we can use other Numpy functions to create a new array and then use the