努比。Python中的倒数()

这个 努比。互惠的 是一个数学函数,用于计算输入数组中所有元素的倒数。

null

语法: 努比。倒数(x,/,out=None,*,其中=True) 参数:

十、 [array_like] : 需要测试其元素的输入数组或对象。

出来 [ndarray,可选] : 存储结果的位置。 –> 如果提供,它必须具有输入广播到的形状。 –> 如果未提供或没有,则返回新分配的数组。

**kwargs: 允许将参数的关键字可变长度传递给函数。用于处理函数中的命名参数。

其中[array_like,可选]: 真值意味着在该位置计算通用函数(ufunc),假值意味着不在输出中使用该值。

返回: y: 恩达雷。如果x是标量,这就是标量。

注: 对于绝对值大于1的整数参数,由于Python处理整数除法的方式,结果始终为零。对于整数0,结果是溢出。

代码#1:

# Python3 code demonstrate reciprocal() function
# importing numpy
import numpy as np
in_num = 2.0
print ( "Input  number : " , in_num)
out_num = np.reciprocal(in_num)
print ( "Output number : " , out_num)


输出:

Input  number :  2.0
Output number :  0.5

代码#2:

# Python3 code demonstrate reciprocal() function
# importing numpy
import numpy as np
in_arr = [ 2. , 3. , 8. ]
print ( "Input array : " , in_arr)
out_arr = np.reciprocal(in_arr)
print ( "Output array : " , out_arr)


输出:

Input array :  [2.0, 3.0, 8.0]
Output array :  [ 0.5         0.33333333  0.125     ]

代码#3: 倒数()函数中出现异常。结果总是零。

# Python3 code demonstrate Exception in reciprocal() function
# importing numpy
import numpy as np
in_arr = [ 2 , 3 , 8 ]
print ( "Input array : " , in_arr)
out_arr = np.reciprocal(in_arr)
print ( "Output array : " , out_arr)


输出:

Input array :  [2, 3, 8]
Output array :  [0 0 0]
© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享