Thursday, November 20, 2025
HomeLanguagesnumpy.fabs() in Python

numpy.fabs() in Python

numpy.fabs() function is used to compute the absolute values element-wise. This function returns the absolute values (positive magnitude) of the data in arr. It always return absolute values in floats.

Syntax : numpy.fabs(arr, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, ufunc ‘fabs’)

Parameters :
arr : [array_like] The array of numbers for which the absolute values are required.
out : [ndarray, optional] 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.
**kwargs : Allows to pass keyword variable length of argument to a function. It is used when we want to handle named argument in a function.
where : [array_like, optional] True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone.

Return : [ndarray or scalar] The absolute values of arr, the returned values are always floats.

Code #1 : Working




# Python program explaining
# fabs() function
  
import numpy as geek
in_num = 10
print ("Input  number : ", in_num)
    
out_num = geek.fabs(in_num) 
print ("Absolute value  of positive  input number : ", out_num) 


Output :

Input  number :  10
Absolute value  of positive  input number :  10.0

 
Code #2 :




# Python program explaining
# fabs() function
  
import numpy as geek
in_num = -9.0
print ("Input  number : ", in_num)
    
out_num = geek.fabs(in_num) 
print ("Absolute value  of negative input number : ", out_num) 


Output :

Input  number :  -9.0
Absolute value  of negative input number :  9.0

 
Code #3 :




# Python program explaining
# fabs() function
  
import numpy as geek
  
in_arr = [2, 0, -2, -5]
print ("Input array : ", in_arr)
    
out_arr = geek.fabs(in_arr) 
print ("Output absolute array : ", out_arr) 


Output :

Input array :  [2, 0, -2, -5]
Output absolute array :  [ 2.  0.  2.  5.]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6777 POSTS0 COMMENTS
Nicole Veronica
11925 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6905 POSTS0 COMMENTS
Ted Musemwa
7162 POSTS0 COMMENTS
Thapelo Manthata
6861 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS