numpy.float_power(arr1,arr2,out = None,其中= True,強製轉換=“ same_kind”,order =“ K”,dtype = None):
來自第一個數組的數組元素被提升為來自第二個元素的元素的冪(所有情況都逐個元素發生)。 arr1和arr2必須具有相同的形狀。
float_power與冪函數的不同之處在於,將整數float16和float32提升為float64的最小精度為float64,因此結果始終是不精確的。此函數將為負冪返回可用結果,而對於+ ve冪則很少溢出。
參數:
arr1 : [array_like]Input array or object which works as base. arr2 : [array_like]Input array or object which works as exponent. out : [ndarray, optional]Output array with same dimensions as Input array, placed with result. **kwargs : Allows you to pass keyword variable length of argument to a function. It is used when we want to handle named argument in a function. 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.
返回:
An array with elements of arr1 raised to exponents in arr2
代碼1:將arr1提升為arr2
# Python program explaining
# float_power() function
import numpy as np
# input_array
arr1 = [2, 2, 2, 2, 2]
arr2 = [2, 3, 4, 5, 6]
print ("arr1 : ", arr1)
print ("arr1 : ", arr2)
# output_array
out = np.float_power(arr1, arr2)
print ("\nOutput array : ", out)
輸出:
arr1 : [2, 2, 2, 2, 2] arr1 : [2, 3, 4, 5, 6] Output array : [ 4. 8. 16. 32. 64.]
代碼2:將arr1的元素提高到指數2
# Python program explaining
# float_power() function
import numpy as np
# input_array
arr1 = np.arange(8)
exponent = 2
print ("arr1 : ", arr1)
# output_array
out = np.float_power(arr1, exponent)
print ("\nOutput array : ", out)
輸出:
arr1 : [0 1 2 3 4 5 6 7] Output array : [ 0. 1. 4. 9. 16. 25. 36. 49.]
代碼3:如果arr2具有-ve元素,則float_power處理結果
# Python program explaining
# float_power() function
import numpy as np
# input_array
arr1 = [2, 2, 2, 2, 2]
arr2 = [2, -3, 4, -5, 6]
print ("arr1 : ", arr1)
print ("arr2 : ", arr2)
# output_array
out = np.float_power(arr1, arr2)
print ("\nOutput array : ", out)
輸出:
arr1 : [2, 2, 2, 2, 2] arr2 : [2, -3, 4, -5, 6] Output array : [ 4.00000000e+00 1.25000000e-01 1.60000000e+01 3.12500000e-02 6.40000000e+01]
參考文獻:
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.float_power.html#numpy.float_power
。
相關用法
注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 numpy.float_power() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。