I am trying to learn Python by completing a tutorial, specifically I am trying to make a Gaussian function. I tried to search it up on the internet and on one website, they advised to change the name of the variable but it didn't change the error. It is still there. Please help, what do I do? This is the website that I've used to try to make my Gaussian function: https://education.molssi.org/python-data-analysis/03-data-fitting/index.html
Here's my code below:
z = [2,5,7]
y = [9,0,-1]
z = np.asarray(z)
y = np.asarray(y)
def Gauss (z,A, B):
y = A*np.exp(-1*B*x**2)
return y
parameters, covariance = curve_fit(x, y, Gauss)
fit_A = parameters[2]
fit_B = parameters[0]
fit_y = Gauss(z, fit_A, fit_B)
plt.scatter(z, y, label = 'Gauss')
plt.scatter(z, fit_y, color = 'lightcoral')
plt.legend()
And this is the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[71], line 8
4
5
def
Gauss (z,A, B):
6 y = A*np.exp(-1*B*x**2)
7
return
y
----> 8 parameters, covariance = curve_fit(x, y, Gauss)
9 fit_A = parameters[2]
10 fit_B = parameters[0]
11 fit_y = Gauss(z, fit_A, fit_B)
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/scipy/optimize/_minpack_py.py:907, in curve_fit(f, xdata, ydata, p0, sigma, absolute_sigma, check_finite, bounds, method, jac, full_output, nan_policy, **kwargs)
594 """
595 Use non-linear least squares to fit a function, f, to data.
596
(...) 903 array([5.00000000e+05, 1.00000000e-02, 1.49999999e+01])
904 """
905
if
p0
is
None
:
906 # determine number of parameters by inspecting the function
--> 907 sig = _getfullargspec(f)
908 args = sig.args
909
if
len(args) < 2:
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/scipy/_lib/_util.py:487, in getfullargspec_no_self(func)
466
def
getfullargspec_no_self(func):
467 """inspect.getfullargspec replacement using inspect.signature.
468
469 If func is a bound method, do not list the 'self' parameter.
(...) 485
486 """
--> 487 sig = wrapped_inspect_signature(func)
488 args = [
489 p.name
for
p
in
sig.parameters.values()
490
if
p.kind
in
[inspect.Parameter.POSITIONAL_OR_KEYWORD,
491 inspect.Parameter.POSITIONAL_ONLY]
492 ]
493 varargs = [
494 p.name
for
p
in
sig.parameters.values()
495
if
p.kind == inspect.Parameter.VAR_POSITIONAL
496 ]
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/scipy/_lib/_util.py:44, in wrapped_inspect_signature(callable)
42
def
wrapped_inspect_signature(callable):
43 """Get a signature object for the passed callable."""
---> 44
return
inspect.signature(callable,
45 annotation_format=annotationlib.Format.FORWARDREF)
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py:3323, in signature(obj, follow_wrapped, globals, locals, eval_str, annotation_format)
3320
def
signature(obj, *, follow_wrapped=
True
, globals=
None
, locals=
None
, eval_str=
False
,
3321 annotation_format=Format.VALUE):
3322 """Get a signature object for the passed callable."""
-> 3323
return
Signature.from_callable(obj, follow_wrapped=follow_wrapped,
3324 globals=globals, locals=locals, eval_str=eval_str,
3325 annotation_format=annotation_format)
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py:3038, in Signature.from_callable(cls, obj, follow_wrapped, globals, locals, eval_str, annotation_format)
3033 u/classmethod
3034
def
from_callable(cls, obj, *,
3035 follow_wrapped=
True
, globals=
None
, locals=
None
, eval_str=
False
,
3036 annotation_format=Format.VALUE):
3037 """Constructs Signature for the given callable object."""
-> 3038
return
_signature_from_callable(obj, sigcls=cls,
3039 follow_wrapper_chains=follow_wrapped,
3040 globals=globals, locals=locals, eval_str=eval_str,
3041 annotation_format=annotation_format)
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py:2436, in _signature_from_callable(obj, follow_wrapper_chains, skip_bound_arg, globals, locals, eval_str, sigcls, annotation_format)
2426 _get_signature_of = functools.partial(_signature_from_callable,
2427 follow_wrapper_chains=follow_wrapper_chains,
2428 skip_bound_arg=skip_bound_arg,
(...) 2432 eval_str=eval_str,
2433 annotation_format=annotation_format)
2435
if
not
callable(obj):
-> 2436
raise
TypeError
('
{!r}
is not a callable object'.format(obj))
2438
if
isinstance(obj, types.MethodType):
2439 # In this case we skip the first parameter of the underlying
2440 # function (usually `self` or `cls`).
2441 sig = _get_signature_of(obj.__func__)
TypeError: array([2, 5, 7]) is not a callable object