What is the fix function in NumPy?

The fix function is used to round a decimal value towards zero. It comes as part of NumPy, which is a library of the high-level programming language Python.

To access the fix function, we must import the NumPy library at the start of the program:

import numpy

Syntax

numpy.fix(x, out=None)

Parameters

The fix function takes in the following parameters:

  • x - an array of floats or a single numerical value to be rounded to the nearest zero.
  • out - (optional) the function’s output is stored at this location.

Return value

The fix function returns an array and has the same dimensions as x. The values are of type float.

Example

The following program demonstrates how to apply the fix function on an array of floats.

The return value is printed using the built-in print function that comes with Python.

import numpy
print(numpy.fix([4.55, 12.31, -512.2313, 0.541]))

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved