如何使用math.sqrt()? [英] how to use math.sqrt ()?

查看:346
本文介绍了如何使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆