NumPy | Get the Powers of Array Values Element-Wise Last Updated : 09 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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("Original array ") print("array1 ", sample_array1) print("array2 ", sample_array2) # calculating element-wise power power_array = np.power(sample_array1, sample_array2) print("power to the array1 and array 2 : ", power_array) Output: Original array array1 [0 1 2 3 4] array2 [0 2 4 6 8] power to the array1 and array 2 : [ 1 1 16 729 65536] SyntaxSyntax: numpy.power(arr1, arr2, out = None, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None) Parameters: arr1: Input array or object which works as base. arr2: Input array or object which works as exponent. out: Output array with same dimensions as Input array, placed with the result. 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.More ExamplesLet's look at more Python programs that shows how to find the Power of elements in the array using the power() function of the NumPy library. Example 1: Computing the same power for every element in the array. Python3 # import required module import numpy as np # creating the array array = np.arange(8) print("Original array") print(array) # computing the power of array print("power of 3 for every element-wise:") print(np.power(array, 3)) Output: Original array [0 1 2 3 4 5 6 7] power of 3 for every element-wise: [ 0 1 8 27 64 125 216 343] Example 2: Computing the power of decimal value. Python3 # import required modules import numpy as np # creating the array sample_array1 = np.arange(5) # initialization the decimal number sample_array2 = [1.0, 2.0, 3.0, 3.0, 2.0] print("Original array ") print("array1 ", sample_array1) print("array2 ", sample_array2) # calculating element-wise power power_array = np.power(sample_array1, sample_array2) print("power to the array1 and array 2 : ", power_array) Output: Original array array1 [0 1 2 3 4] array2 [1.0, 2.0, 3.0, 3.0, 2.0] power to the array1 and array 2 : [ 0. 1. 8. 27. 16.] Note: you can not compute negative power Example 3: Computing negative power Python3 # importing module import numpy as np # creating the array array = np.arange(8) print("Original array") print(array) print("power of 3 for every element-wise:") # computing the negative power element print(np.power(array, -3)) Output: Comment More infoAdvertise with us Next Article NumPy | Get the Powers of Array Values Element-Wise kumar_satyam Follow Improve Article Tags : Python Python-numpy Python numpy-program Python numpy-arrayManipulation Practice Tags : python Similar Reads How to get the powers of an array values element-wise in Python-Pandas? Let's see how to get the powers of an array values element-wise. Dataframe/Series.pow() is used to calculate the power of elements either with itself or with other Series provided. This function is applicable for real numbers only, and doesn't give results for complex numbers. So let's see the progr 2 min read 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 How to calculate the element-wise absolute value of NumPy array? 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 2 min read Find the length of each string element in the Numpy array NumPy builds on (and is a successor to) the successful Numeric array object. Its goal is to create the corner-stone for a useful environment for scientific computing. NumPy provides two fundamental objects: an N-dimensional array object (ndarray) and a universal function object (ufunc). In this post 3 min read NumPy ndarray.T | Get View of Transposed Array The NumPy ndarray.T attribute finds the view of the transposed Array. It can transpose any array having a dimension greater than or equal to 2. It works similarly to the numpy.transpose() method but it is easy and concise to use. SyntaxSyntax: ndarray.T Returns Transpose of given arrayExamplesLet's 1 min read Select an element or sub array by index from a Numpy Array The elements of a NumPy array are indexed just like normal arrays. The index of the first element will be 0 and the last element will be indexed n-1, where n is the total number of elements. Selecting a single element from a NumPy array Each element of these ndarrays can be accessed using its index 2 min read NumPy ndarray.__mul__() Method | Element Wise Multiplication of Array The ndarray.__mul__() method does an element-wise multiplication of NumPy ndarray to a particular value that is provided as the parameter. Example Python3 import numpy as np gfg = np.array([1, 2.5, 3, 4.8, 5]) print(gfg.__mul__(5)) Output[ 5. 12.5 15. 24. 25. ] SyntaxSyntax: ndarray.__mul__($self, v 1 min read Python | numpy.array_split() method With the help of numpy.array_split() method, we can get the splitted array of having different dimensions by using numpy.array_split() method. Syntax : numpy.array_split() Return : Return the splitted array of one dimension. Example #1 : In this example we can see that by using numpy.array_split() m 1 min read NumPy ndarray.size() Method | Get Number of Elements in NumPy Array The ndarray.size() method returns the number of elements in the NumPy array. It works the same as np.prod(a.shape), i.e., the product of the dimensions of the array. Example Python3 import numpy as np arr = np.zeros((3, 4, 2), dtype = np.complex128) gfg = arr.size print (gfg) Output : 24Syntax Synta 1 min read Computing e^x element-wise in a NumPy array In this article, we will discuss how to compute e^x for each element of a NumPy array. Example : Input : [1, 3, 5, 7] Output : [2.7182817, 20.085537, 148.41316, 1096.6332] Explanation : e^1 = 2.7182817 e^3 = 20.085537 e^5 = 148.41316 e^7 = 1096.6332 We will be using the numpy.exp() method to calcula 2 min read Like