- 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

# Set the first array elements raised to powers from second array element-wise in Numpy

To set the first array elements raised to powers from second array, element-wise, use the **numpy.power()** method in Python. Here, the 1st parameter is the base and the 2nd exponents.

Raise each base in x1 to the positionally-corresponding power in x2. x1 and x2 must be broadcastable to the same shape. An integer type raised to a negative integer power will raise a ValueError. Negative values raised to a non-integral value will return nan. To get complex results, cast the input to complex, or specify the dtype to be complex.

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 −

arr = np.array([5, 10, 25, 30, 40, 50])

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)

Set the exponent −

p = [2, 3, 2, 3, 2, 3]

To set the first array elements raised to powers from second array, element-wise, use the numpy.power() method. Here, the 1st parameter is the base and the 2nd exponents −

print("\nResult...\n",np.power(arr, p))

## Example

import numpy as np # Create an array arr = np.array([5, 10, 25, 30, 40, 50]) # 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) # Set the exponent p = [2, 3, 2, 3, 2, 3] # To set the first array elements raised to powers from second array, element-wise, use the numpy.power() method in Python # Here, the 1st parameter is the base and the 2nd exponents print("\nResult...\n",np.power(arr, p))

## Output

Array... [ 5 10 25 30 40 50] Our Array type... int64 Our Array Dimension... 1 Our Array Shape... (6,) Result... [ 25 1000 625 27000 1600 125000]

- Related Questions & Answers
- Return the bases when first array elements are raised to powers from second array in Python
- Return element-wise base masked array raised to power from second array in Numpy
- Compute the bit-wise NOT of an array element-wise in Numpy
- Sort the second array according to the elements of the first array in JavaScript
- Subtracting array in JavaScript Delete all those elements from the first array that are also included in the second array
- Compute the bit-wise NOT of a One-Dimensional array element-wise in Numpy
- Compute the bit-wise NOT of a Two-Dimensional array element-wise in Numpy
- Compute the truth value of an array AND to another array element-wise in Numpy
- Compute the truth value of an array OR to another array element-wise in Numpy
- Compute the truth value of an array XOR another array element-wise in Numpy
- Compute the truth value of NOT an array element-wise in Numpy
- Return the base 10 logarithm of the input array element-wise in Numpy
- Compute the bit-wise XOR of a 1D and a 2D array element-wise in Numpy
- Compute the bit-wise AND of a 1D and a 2D array element-wise in Numpy
- Compute the bit-wise OR of a 1D and a 2D array element-wise in Numpy