Numpy库之符号函数sign()的介绍及用法

hxy    2019-08-19 08:37

np.sign()是一个符号函数,用于把函数的符号析离出来,定义如下:

 

python示例代码:
#%%
import numpy as np


data = 1
print(data,'=>', np.sign(data))

data = 0
print(data,'=>', np.sign(data))

data = -1
print(data,'=>', np.sign(data))

data = [-100, -0.1, 0, 0.00001, 4, 0.0]
print(data,'=>', np.sign(data))
运行结果:
1 => 1
0 => 0
-1 => -1
[-100, -0.1, 0, 1e-05, 4, 0.0] => [-1. -1.  0.  1.  1.  0.]
Last Modified: 2019-09-09 19:10
Views: 6.5K

[[total]] comments

Post your comment
  1. [[item.time]]
    [[item.user.username]] [[item.floor]]Floor
  2. Click to load more...
  3. Post your comment