Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Return the result of the negative power to which the input value is raised with scimath in Python
To return the result of the power to which the input value is raised with scimath, use the scimath.power() method in Python. Returns x to the power p, i.e. the result of x**p. If x and p are scalars, so is out, otherwise an array is returned. If x contains negative values, the output is converted to the complex domain. The parameter x is the input value
The parameter p is the power(s) to which x is raised. If x contains multiple values, p has to either be a scalar, or contain the same number of values as x. In the latter case, the result is x[0]**p[0], x[1]**p[1], ....
Steps
At first, import the required libraries −
import numpy as np
Creating a numpy array using the array() method −
arr = np.array([2, 4, 8, 16, 32])
Display the array −
print("Our Array...<br>",arr)
Check the Dimensions −
print("\nDimensions of our Array...<br>",arr.ndim)
Get the Datatype −
print("\nDatatype of our Array object...<br>",arr.dtype)
Get the Shape −
print("\nShape of our Array object...<br>",arr.shape)
To return the result of the power to which the input value is raised with scimath, use the scimath.power() method in Python −
print("\nResult...<br>",np.emath.power(arr, -2))
Example
import numpy as np
# Creating a numpy array using the array() method
arr = np.array([2, 4, 8, 16, 32])
# Display the array
print("Our Array...<br>",arr)
# Check the Dimensions
print("\nDimensions of our Array...<br>",arr.ndim)
# Get the Datatype
print("\nDatatype of our Array object...<br>",arr.dtype)
# Get the Shape
print("\nShape of our Array object...<br>",arr.shape)
# To return the result of the power to which the input value is raised with scimath, use the scimath.power() method in Python
print("\nResult...<br>",np.emath.power(arr, -2))
Output
Our Array... [ 2 4 8 16 32] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (5,) Result... [0.25 0.0625 0.015625 0.00390625 0.00097656]
