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.]