如何使用math.sqrt()? [英] how to use math.sqrt ()?
问题描述
大家好,我是python的初学者,我尝试使用math.sqrt()来计算距离。
print math.sqrt(float(data [data] 0] [0]) - float(k_cluster [0] [0] ** 2)+ float(data [0] [1]) - float(k_cluster [0] [1] ** 2)))
例如:
data [0] = 12.1
data [0] [0] = 15.125
数据[0] [1] = 13.214
k_cluster [0] [0] = 5.34
k_cluster [0] [1] = 6.78
当我使用上面的代码时告诉我数学域错误,但如果没有math.sqrt()它正常工作
你知道问题是什么吗?
检查你的括号的位置
hi guys, i'm beginner of python, i trying use math.sqrt() to count distance.
print math.sqrt(float(data[0][0]) - float(k_cluster[0][0]**2) + float(data[0][1]) - float(k_cluster[0][1]**2)))
for example:
data[0] = 12.1
data[0][0] = 15.125
data[0][1] = 13.214
k_cluster[0][0] = 5.34
k_cluster[0][1] = 6.78
when i use code above it tell me math domain error, but if without math.sqrt() it work normally
do you know what the problem??
Check the placement of your parenthesis.
这篇关于如何使用math.sqrt()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!