How to calculate the element-wise absolute value of NumPy array? Last Updated : 29 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Let's see the program for finding the element-wise absolute value of NumPy array. For doing this task we are using numpy.absolute() function of NumPy library. This mathematical function helps to calculate the absolute value of each element in the array. Syntax: numpy.absolute(arr, out = None, ufunc ‘absolute’) Return: An array with absolute value of each element. Let's see an example: Example 1: Element-wise absolute value of 1d-array. Python3 # import library import numpy as np # create a numpy 1d-array array = np.array([1, -2, 3]) print("Given array:\n", array) # find element-wise # absolute value rslt = np.absolute(array) print("Absolute array:\n", rslt) Output: Given array: [ 1 -2 3] Absolute array: [1 2 3] Example 2: Element-wise absolute value of 2d-array. Python3 # import library import numpy as np # create a numpy 2d-array array = np.array([[1, -2, 3], [-4, 5, -6]]) print("Given array:\n", array) # find element-wise # absolute value rslt = np.absolute(array) print("Absolute array:\n", rslt) Output: Given array: [[ 1 -2 3] [-4 5 -6]] Absolute array: [[1 2 3] [4 5 6]] Example 3: Element-wise absolute value of 3d-array. Python3 # import library import numpy as np # create a numpy 3d-array array = np.array([ [[1, -2, 3], [-4, 5, -6]], [[-7.5, -8.22, 9.0], [10.0, 11.5, -12.5]] ]) print("Given array:\n", array) # find element-wise # absolute value rslt = np.absolute(array) print("Absolute array:\n", rslt) Output: Given array: [[[ 1. -2. 3. ] [ -4. 5. -6. ]] [[ -7.5 -8.22 9. ] [ 10. 11.5 -12.5 ]]] Absolute array: [[[ 1. 2. 3. ] [ 4. 5. 6. ]] [[ 7.5 8.22 9. ] [10. 11.5 12.5 ]]] Comment More infoAdvertise with us Next Article How to calculate the element-wise absolute value of NumPy array? A ankthon Follow Improve Article Tags : Python Python-numpy Python numpy-program Python numpy-Mathematical Function Practice Tags : python Similar Reads NumPy| How to get the unique elements of an Array To find unique elements of an array we use the numpy.unique() method of the NumPy library in Python. It returns unique elements in a new sorted array. Example: Python3 import numpy as np arr = np.array([1, 2, 3, 1, 4, 5, 2, 5]) unique_elements = np.unique(arr) print(unique_elements) Output: [1 2 3 4 2 min read NumPy | Get the Powers of Array Values Element-Wise To calculate the power of elements in an array we use the numpy.power() method of NumPy library. It raises the values of the first array to the powers in the second array. Example:Python3 import numpy as np # creating the array sample_array1 = np.arange(5) sample_array2 = np.arange(0, 10, 2) print(" 3 min read How to Calculate the Mode of NumPy Array? The goal here is to calculate the mode of a NumPy array, which refers to identifying the most frequent value in the array. For example, given the array [1, 1, 2, 2, 2, 3, 4, 5], the mode is 2, as it appears most frequently. Let's explore different approaches to accomplish this. Using scipy.stats.mod 2 min read How to Calculate the determinant of a matrix using NumPy? The determinant of a square matrix is a special number that helps determine whether the matrix is invertible and how it transforms space. It is widely used in linear algebra, geometry and solving equations. NumPy provides built-in functions to easily compute the determinant of a matrix, let's explor 2 min read Calculate average values of two given NumPy arrays Finding average of NumPy arrays is quite similar to finding average of given numbers. We just have to get the sum of corresponding array elements and then divide that sum with the total number of arrays. Let's see an example: Example 1: Calculate average values of two given NumPy 1d-arrays Python3 # 1 min read Like