Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用Python编写这个公式?_Python_Numpy_Formula - Fatal编程技术网

如何用Python编写这个公式?

如何用Python编写这个公式?,python,numpy,formula,Python,Numpy,Formula,我有一个公式,我正在努力编写它的Python等价物: 其中I(x,y)是numpy数组形式的图像,其强度值可使用行-列索引访问。xbar是已知的质心x坐标 我的代码尝试如下: # centroid is a tuple of (x,y) of the coordinate position. image is a 2d array of the image. import scipy.integrate as integrate height, width = image.shape[0:2

我有一个公式,我正在努力编写它的Python等价物:

其中I(x,y)是numpy数组形式的图像,其强度值可使用行-列索引访问。xbar是已知的质心x坐标

我的代码尝试如下:

# centroid is a tuple of (x,y) of the coordinate position. image is a 2d array of the image.
import scipy.integrate as integrate

height, width = image.shape[0:2]

intensity_func = lambda x,y: image[y,x]
denom = int.dblquad(intensity_func, 0, height, lambda x: 0, lambda x: width)
x_f = lambda x,y: (x-centroid[0])**2 * intensity_func(x,y)
x_num = int.nquad(x_f, [[0, width],[0, height]])
sig_x = np.sqrt(x_num[0]/denom[0])

print 4*sig_x

到底是什么问题?我不知道怎么做!我知道我的代码不太清楚,也不知道如何正确地用python编写公式。首先,我不建议将一些包作为
int
导入,因为这是一个保留的python关键字。第二,似乎平方根最终丢失了。对于其余部分,它似乎足够复杂,可以:)当它运行时,您遇到了什么问题?谢谢您的回答。我得到了这个错误:ng:已经达到了最大细分数(50)。如果增加限值不会产生任何改善,建议分析被积函数以确定困难。如果可以确定局部困难的位置(奇异性、不连续性),则可以通过拆分区间并调用子区间上的积分器来获得收益。也许应该使用专用的积分器。警告。警告(消息,集成警告)Ooops。超越我。我的理解是,您的集成太笼统、太广泛。警告建议您在多个时间间隔上使用专门的积分公式。但这只是一个警告,你仍然应该得到一个结果。