Replies: 7 comments 4 replies
-
@bguttel is https://lmfit.github.io/lmfit-py/examples/example_two_dimensional_peak.html helpful? |
Beta Was this translation helpful? Give feedback.
-
@bguttel Right, I see your point that requiring |
Beta Was this translation helpful? Give feedback.
-
@bguttel I think it is reasonable to return a 2D as you suggest and then make sure that any 2D (or other) model gets flattened in the fit -- that should happen already. |
Beta Was this translation helpful? Give feedback.
-
The advantage of this is that you can fit data even if it is not on a regular grid. If the data is not on a regular grid one cannot represent it in terms of the two 1D arrays of length N and M to make up a 2D NxM array. I'm open to input, but my understanding is that scripts with the meshgrid step will all work perfectly? |
Beta Was this translation helpful? Give feedback.
-
@mpmdean thanks for the clarification - that does seem like a compelling use case. I think perhaps the only example we have is slightly confusing. Perhaps the need to use |
Beta Was this translation helpful? Give feedback.
-
@mpmdean oh no worries -- and I'm not able to do it any time soon either! Maybe @bguttel would be willing to provide or improve the example? |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late response. Following @mpmdean explanation, I think works it would be helpful to add a semi-example with 2d data ( X, Y = np.meshgrid(x, y)
model = lmfit.models.Gaussian2dModel()
params = model.guess(Z.flatten(), X.flatten(), Y.flatten())
result = model.fit(Z, x=X, y=Y, params=params) Notice that I also had to flatten the matrices since the |
Beta Was this translation helpful? Give feedback.
-
It seems to me that the
gaussian2d
function underlineshapes
just multiply two 1D-gaussians, and since this is the normal numpy multiplication it is only element-wise and hence the result is also one-dimensional (with the same shape).In practice it is the diagonal of the expected matrix.
I would say the multiplication needs to be the numpy.outer multiplication. If that's true I can try and write it down..
Beta Was this translation helpful? Give feedback.
All reactions