Python np.sqrt中的奇异性

Python np.sqrt中的奇异性,python,numpy,sqrt,Python,Numpy,Sqrt,奇怪的运行时警告:在sqrt中遇到无效值 我正在进行一项任务,我从hdf5文件中获取大量粒子(128**3)的位置,然后计算它们之间的相对距离 运行代码时,我在sqrt函数中检测到意外的RuntimeWarning。在研究代码时,我从以下几行中找出了问题: #This lines presented the problem ((Pos-Pos[0])[:,0]**2) np.sqrt(((Pos-Pos[0])[:,0]**2)) #This lines do not present the

奇怪的运行时警告:在sqrt中遇到无效值

我正在进行一项任务,我从hdf5文件中获取大量粒子(128**3)的位置,然后计算它们之间的相对距离

运行代码时,我在sqrt函数中检测到意外的RuntimeWarning。在研究代码时,我从以下几行中找出了问题:

#This lines presented the problem
((Pos-Pos[0])[:,0]**2)
np.sqrt(((Pos-Pos[0])[:,0]**2))

#This lines do not present the problem
((Pos-Pos[0])[:,0]**2)[1:]
np.sqrt(((Pos-Pos[0])[1:,0]**2)[1:])

#This lines do not present the problem
((Pos-Pos[0])[:,0]**2)[:100]
np.sqrt(((Pos-Pos[0])[:,0]**2)[:100])

#My proposition to solve it
((Pos-Pos[0])[:,0]**2)
np.sqrt(((Pos-Pos[0])[:,0]**2)+1e-10)

我不太明白这场麻烦的性质。你能帮我更好地理解这一点吗?

嗨,欢迎来到SO。但是什么是
Pos
?这有助于提供重现您的问题的解决方案。对不起,您是对的。Pos是一个数据数组,其形状为(128**3,3),包含-0.5和0.5之间的值。您好,欢迎使用SO。但是什么是
Pos
?这有助于提供重现您的问题的解决方案。对不起,您是对的。Pos是一个数据数组,其形状为(128**3,3),包含介于-0.5和0.5之间的值。