当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.copysign()用法及代码示例


numpy.copysign(arr1,arr2,out = None,其中= True,强制转换=“ same_kind”,order =“ K”,dtype = None):此数学函数可帮助用户更改arr1和arr2的符号。 arr1或arr2都可以是列表/序列或标量值。如果是顺序,则两者必须具有相同的尺寸;否则,arr2可以是一个标量值。

参数:
arr1 : [array_like]Input array, values to change sign of.
arr2 : [array_like]Input array, values to change sign of.
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.

返回: x1 with sign of x2.



代码1:

# Python program illustrating  
# copysign() method  
import numpy as np  
  
arr1 = [1, -23, +34, 11] 
arr2 = [-1, 2, -3, -4] 
  
print ("arr1:", arr1) 
print ("arr2:", arr2) 
  
print ("\nCheck sign of arr1:", np.signbit(arr1)) 
print ("\nCheck sign of arr2:", np.signbit(arr1)) 
print ("\nCheck for copysign:", np.signbit(np.copysign(arr1, arr2)))

输出:

arr1: [1, -23, 34, 11]
arr2: [-1, 2, -3, -4]

Check sign of arr1: [False  True False False]
Check sign of arr2: [False  True False False]
Check for copysign: [ True False  True  True]


代码2:

# Python program illustrating  
# copysign() method  
import numpy as np  
  
arr1 = [1, -23, +34, 11] 
  
print ("\nCheck sign of arr2:", np.signbit(arr1)) 
print ("\nCheck for copysign:", np.signbit(np.copysign(arr1, -3)))

输出:

Check sign of arr2: [False  True False False]
Check for copysign: [ True  True  True  True]


相关用法


注:本文由纯净天空筛选整理自Mohit Gupta_OMG 大神的英文原创作品 numpy.copysign() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。