我是Python的新手。我正在尝试使用给定的数据点拟合2D高斯。这是我的代码:
import scipy.optimize as opt
import numpy as np
import pylab as plt
from fftfits import get_image
filename =
'../astro_data/trial23_LSST_convolved_noise0.fits'
image = get_image(filename)
limits = [0,3541,0,3541]
def twod_gaussian(xy, amplitude, x0, y0, sigma_x, sigma_y):
'''Calculating 2D Gaussian from 2D data.'''
return amplitude * np.exp(-((xy[0]-
x0)**2/(2*sigma_x**2)+(xy[1]-y0)**2/(2*sigma_y**2)))
side_x = np.linspace(limits[0],limits[1],3542)
side_y = np.linspace(limits[2],limits[3],3542)
X,Y = np.meshgrid(side_x, side_y)
size = X.shape
x1d = np.reshape(X,(1,np.prod(size)))
y1d = np.reshape(Y,(1,np.prod(size)))
xydata = np.vstack((x1d, y1d))
zdata = np.reshape(image,(1,np.prod(size)))
popt, pcov = opt.curve_fit(twod_gaussian, xydata, zdata)
print(popt)
数据大小为3542 * 3542。引发的错误是这样的:
raise TypeError('Improper input: N=%s must not exceed M=%s' % (n, m))
TypeError: Improper input: N=5 must not exceed M=1
我知道计算机抱怨有5个变量和只有1个数据点,但是在查看其他人发布的类似问题后,我仍然找不到我做错了什么地方:(