

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Calculate the absolute value of float values in Numpy
To return the absolute value of float values, use the numpy.fabs() method in Python Numpy. This function returns the absolute values (positive magnitude) of the data in x. Complex values are not handled, use absolute to find the absolute values of complex data.
The out is 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. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
Steps
At first, import the required library −
import numpy as np
Create an array with float type using the array() method −
arr = np.array([76.7, 28.5, 91.4, -100.8, -120.2, 150.4, 200.7])
Display the array −
print("Array...\n", arr)
Get the type of the array −
print("\nOur Array type...\n", arr.dtype)
Get the dimensions of the Array −
print("\nOur Array Dimension...\n",arr.ndim)
Get the shape of the Array −
print("\nOur Array Shape...\n",arr.shape)
To return the absolute value of float values, use the numpy.fabs() method in Python Numpy −
print("\nResult...\n",np.fabs(arr))
Example
import numpy as np # Create an array with float type using the array() method arr = np.array([76.7, 28.5, 91.4, -100.8, -120.2, 150.4, 200.7]) # Display the array print("Array...\n", arr) # Get the type of the array print("\nOur Array type...\n", arr.dtype) # Get the dimensions of the Array print("\nOur Array Dimension...\n",arr.ndim) # Get the shape of the Array print("\nOur Array Shape...\n",arr.shape) # To return the absolute value of float values, use the numpy.fabs() method in Python Numpy print("\nResult...\n",np.fabs(arr))
Output
Array... [ 76.7 28.5 91.4 -100.8 -120.2 150.4 200.7] Our Array type... float64 Our Array Dimension... 1 Our Array Shape... (7,) Result... [ 76.7 28.5 91.4 100.8 120.2 150.4 200.7]
- Related Questions & Answers
- Calculate the absolute value of complex numbers in Numpy
- Calculate the absolute value element-wise in Numpy
- How to calculate absolute value in Python?
- Get the absolute value of float, int, double and long in Java
- Return the absolute value of a masked Array in NumPy
- How to calculate the absolute values in a pandas series with complex numbers?
- Absolute Deviation and Absolute Mean Deviation using NumPy
- Golang program to calculate the absolute and scale of a vertex.
- Return the default fill value for a masked array with float datatype in Numpy
- Compute the absolute values element-wise and store the result in a new location in Numpy
- What is the maximum value of float in Python?
- JavaScript subtraction of two float values?
- Calculate the n-th discrete difference after setting the number of times values are differenced in Numpy
- Maximum of Absolute Value Expression in C++
- C# Program to get the absolute value of the time