numpy.sign(array [,out])函数用于按元素表示数字的符号。
对于整数输入,如果数组值大于0,则返回1;如果数组值小于0,则返回-1;如果数组值0,则返回0。
用法: numpy.sign()
参数:
array:[数组]输入值。
out :[ndarray,可选]输出数组与结果一起放置。
Return :[ndarray]返回数组的符号。如果数组是标量,则数组的符号将是标量。
代码1:
# Python Program illustrating
# numpy.sign() method
# importing numpy
import numpy as geek
# input arrays
array1 = [1, 0, -13]
array2 = [-1, 0, 15]
# print the input arrays
print ("input array1:", array1)
print ("input array2:", array2)
# determine the sign of integer numbers in an array
print ("\nCheck sign of array1:", geek.sign(array1))
print ("\nCheck sign of array2:", geek.sign(array2))
输出:
array1: [1, 0, -13] array2: [-1, 0, 15] Check sign of array1: [ 1 0 -1] Check sign of array2: [-1 0 1]
代码2:
# Python Program illustrating
# numpy.sign() method
# importing numpy
import numpy as geek
# determine the sign of complex number
print ("\n Check sign of complex input1:", geek.sign(7-3j))
print ("\n Check sign of complex input2:", geek.sign(-7 + 3j))
输出:
Check sign of complex input1: (1+0j) Check sign of complex input2: (-1+0j)
相关用法
注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 numpy.sign() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。