numpy.fix() in Python Last Updated : 08 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The numpy.fix() is a mathematical function that rounds elements of the array to the nearest integer towards zero. The rounded values are returned as floats. Syntax : numpy.fix(a, b = None) Parameters : a : [array_like] Input array to be floated. b : [ndarray, optional] Output array. Return : The array of rounded numbers Code #1 : Working Python3 # Python program explaining # fix() function import numpy as np in_array = [.5, 1.5, 2.5, 3.5, 4.5, 10.1] print ("Input array : \n", in_array) fixoff_values = np.fix(in_array) print ("\nRounded values : \n", fixoff_values) in_array = [.53, 1.54, .71] print ("\nInput array : \n", in_array) fixoff_values = np.fix(in_array) print ("\nRounded values : \n", fixoff_values) in_array = [.5538, 1.33354, .71445] print ("\nInput array : \n", in_array) fixoff_values = np.fix(in_array) print ("\nRounded values : \n", fixoff_values) Output : Input array : [0.5, 1.5, 2.5, 3.5, 4.5, 10.1] Rounded values : [ 0. 1. 2. 3. 4. 10.] Input array : [0.53, 1.54, 0.71] Rounded values : [ 0. 1. 0.] Input array : [0.5538, 1.33354, 0.71445] Rounded values : [ 0. 1. 0.] Code #2 : Working Python3 # Python program explaining # fix() function import numpy as np in_array = [1, 4, 7, 9, 12] print ("Input array : \n", in_array) fixoff_values = np.fix(in_array) print ("\nRounded values : \n", fixoff_values) in_array = [133, 344, 437, 449, 12] print ("\nInput array : \n", in_array) fixoff_values = np.fix(in_array) print ("\nRounded values upto 2: \n", fixoff_values) in_array = [133, 344, 437, 449, 12] print ("\nInput array : \n", in_array) fixoff_values = np.fix(in_array) print ("\nRounded values upto 3: \n", fixoff_values) Output : Input array : [1, 4, 7, 9, 12] Rounded values : [ 1. 4. 7. 9. 12.] Input array : [133, 344, 437, 449, 12] Rounded values upto 2: [ 133. 344. 437. 449. 12.] Input array : [133, 344, 437, 449, 12] Rounded values upto 3: [ 133. 344. 437. 449. 12.] Comment More infoAdvertise with us Next Article numpy.fix() in Python M mohit gupta_omg :) Follow Improve Article Tags : Python Python-numpy Python numpy-Mathematical Function Practice Tags : python Similar Reads numpy.array_repr() in Python numpy.array_repr()function is used to convert an array to a string. Syntax : numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None) Parameters : arr : [array_like] Input array. max_line_width : [int, optional] The maximum number of columns the string should span. Newline cha 2 min read numpy.nan_to_num() in Python numpy.nan_to_num() function is used when we want to replace nan(Not A Number) with zero and inf with finite numbers in an array. It returns (positive) infinity with a very large number and negative infinity with a very small (or negative) number. Syntax : numpy.nan_to_num(arr, copy=True) Parameters 2 min read numpy.ma.fix_invalid() function | Python numpy.ma.fix_invalid() function return input with invalid data masked and replaced by a fill value. Where invalid data means values of nan, inf, etc. Syntax : numpy.ma.fix_invalid(arr, mask = False, copy = True, fill_value = None) Parameter : arr : [array_like] Input array. mask : [sequence, optiona 2 min read numpy.trim_zeros() in Python numpy.trim_zeros() removes the leading and trailing zeros from a 1-D array. It is often used to clean up data by trimming unnecessary zeros from the beginning or end of the array. Example:Pythonimport numpy as np a = np.array([0, 0, 3, 4, 0, 5, 0, 0]) res = np.trim_zeros(a) print(res)Output[3 4 0 5] 2 min read float() in Python Python float() function is used to return a floating-point number from a number or a string representation of a numeric value. Example: Here is a simple example of the Python float() function which takes an integer as the parameter and returns its float value. Python3 # convert integer value to floa 3 min read Like