Difference between the methods power and float_power in NumPy
Start your free 7-days trial now!
Both methods are used to raise each value in the input array by the specified amount.
The key difference is that Numpy's
power(~) method uses the same data-type as the input array to perform the calculation; if your input array only contains integers, then the returned result will also be of type
int. On the other hand,
float_power(~) always uses
float64 for maximum precision.
Here's a simple example:
x = [1,2,3]np.power(x, 2) # Type is int64 since the input is of type int64array([1, 4, 9])
x = [1,2,3]np.float_power(x, 2) # Type is float64array([1., 4., 9.])