def SAM(s1, s2):
"""
Computes the spectral angle mapper between two vectors (in radians).
Parameters:
s1: `numpy array`
The first vector.
s2: `numpy array`
The second vector.
Returns: `float`
The angle between vectors s1 and s2 in radians.
"""
try:
s1_norm = math.sqrt(np.dot(s1, s1))
s2_norm = math.sqrt(np.dot(s2, s2))
sum_s1_s2 = np.dot(s1, s2)
angle = math.acos(sum_s1_s2 / (s1_norm * s2_norm))
except ValueError:
# python math don't like when acos is called with
# a value very near to 1
return 0.0
return angle
评论列表
文章目录