How to calculate the element-wise absolute value of NumPy array? Last Updated : 29 Aug, 2020 Comments Improve Suggest changes 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? 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 How to get element-wise true division of an array using Numpy? True Division in Python3 returns a floating result containing the remainder of the division. To get the true division of an array, NumPy library has a function numpy.true_divide(x1, x2). This function gives us the value of true division done on the arrays passed in the function. To get the element-w 2 min read How to get the n-largest values of an array using NumPy? Let's see the program for how to get the n-largest values of an array using NumPy library. For getting n-largest values from a NumPy array we have to first sort the NumPy array using numpy.argsort() function of NumPy then applying slicing concept with negative indexing. Syntax: numpy.argsort(arr, ax 2 min read How to Calculate Mean Absolute Error in Python? When building machine learning models, our aim is to make predictions as accurately as possible. However, not all models are perfect some predictions will surely deviate from the actual values. To evaluate how well a model performs, we rely on error metrics. One widely used metric for measuring pred 3 min read How to get the floor, ceiling and truncated values of the elements of a numpy array? In this article, let's discuss how to get the floor, ceiling, and truncated values of the elements of a Numpy array. First, we need to import the NumPy library to use all the functions available in it. This can be done with this import statement: import numpy as np Getting the floor value The greate 3 min read How to get values of an NumPy array at certain index positions? Sometimes we need to remove values from the source Numpy array and add them at specific indices in the target array. In NumPy, we have this flexibility, we can remove values from one array and add them to another array. We can perform this operation using numpy.put() function and it can be applied t 4 min read Like