can't multiply sequence by non-int of type 'numpy.float64'

2,084 views
Skip to first unread message

Sydney SHALL

unread,
Jun 16, 2019, 11:51:56 AM6/16/19
to lmfit-py
I am a beginner. I am trying to learn to use LMFit.

I have written a program which models the reproduction of cells.

As expected the output is an exponential growth curve.
Now, I need to learn to use LMFit before I start modifying the program to accommodate real situations.

My little program is modeled on the first example of the manual. Maybe, I should read more of the manual.

How should I proceed?

I get the following error message:


Current_Version/FindCurveParametersLMFitExpV_0_0_1.py')

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/sydney/AnacondaProjects/capital_reproduction/Current_Version/FindCurveParametersLMFitExpV_0_0_1.py", line 77, in <module>
    result = minner.minimize()

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/lmfit/minimizer.py", line 1949, in minimize
    return function(**kwargs)

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/lmfit/minimizer.py", line 1492, in leastsq
    lsout = scipy_leastsq(self.__residual, variables, **lskws)

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/scipy/optimize/minpack.py", line 384, in leastsq
    shape, dtype = _check_func('leastsq', 'func', func, x0, args, n)

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/scipy/optimize/minpack.py", line 26, in _check_func
    res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/lmfit/minimizer.py", line 523, in __residual
    out = self.userfcn(params, *self.userargs, **self.userkws)

  File "/Users/sydney/AnacondaProjects/capital_reproduction/Current_Version/FindCurveParametersLMFitExpV_0_0_1.py", line 65, in fcn2min
    model = (start * np.log(cycles * exp)) + constant

  File "/Users/sydney/anaconda3/lib/python3.7/site-packages/lmfit/parameter.py", line 948, in __rmul__
    return other * self._getval()

TypeError: can't multiply sequence by non-int of type 'numpy.float64'

Sydney

Matt Newville

unread,
Jun 16, 2019, 8:38:46 PM6/16/19
to lmfit-py
On Sun, Jun 16, 2019 at 10:51 AM 'Sydney SHALL' via lmfit-py <lmfi...@googlegroups.com> wrote:
I am a beginner. I am trying to learn to use LMFit.

I have written a program which models the reproduction of cells.

As expected the output is an exponential growth curve.
Now, I need to learn to use LMFit before I start modifying the program to accommodate real situations.

My little program is modeled on the first example of the manual. Maybe, I should read more of the manual.

How should I proceed?

Well,
     File "/Users/sydney/AnacondaProjects/capital_reproduction/Current_Version/FindCurveParametersLMFitExpV_0_0_1.py", line 65, in fcn2min
          model = (start * np.log(cycles * exp)) + constant
     TypeError: can't multiply sequence by non-int of type 'numpy.float64'

suggests that you have a "sequence" (a list or a tuple or perhaps something more exotic, but NOT a numpy array) that you're trying to multiply be a numpy value.  Perhaps `cycles` is a list, and `exp` is meant to be a fitting variable?

All the data in your fitting process should be numpy arrays or plain Python floats, not lists or tuples.  That might explain the problem you're seeing.  If not, post a complete, minimal example that shows the problem you're having.

--Matt

Sydney SHALL

unread,
Jun 17, 2019, 10:45:38 AM6/17/19
to lmfit-py
Dear Matt,

Thanks for the advice. You are of course, quite correct. I have changed my input data to np arrays and now I get the correct answers and a good graphical output.
Thanks muchly.
Sydney

-- Sydney
 
 

Sydney SHALL

unread,
Jun 17, 2019, 11:30:53 AM6/17/19
to lmfit-py


On Sunday, 16 June 2019 16:51:56 UTC+1, Sydney SHALL wrote:

Sydney SHALL

unread,
Jun 17, 2019, 11:33:45 AM6/17/19
to lmfit-py


On Sunday, 16 June 2019 16:51:56 UTC+1, Sydney SHALL wrote:
Reply all
Reply to author
Forward
0 new messages