"AttributeError: 'list' object has no attribute 'ravel'"

10,984

Just do:

return np.array([xdot, ydot])

instead. This should work...

Share:
10,984
emma
Author by

emma

the f in life is for fake. the rest is a lie

Updated on June 05, 2022

Comments

  • emma
    emma almost 2 years

    I have a system of differential equations and need to calculate the Jacobian. The code below throws AttributeError: 'list' object has no attribute 'ravel'. What am I missing?

    import numpy as np
    import numdifftools as ndt
    
    def rhs(z, t=0):
        x,y = z
    
        xdot = (x/5 + y)*(-x**2+1)
        ydot = -x*(-y**2+1)
    
        return [xdot, ydot]
    
    Jfun = ndt.Jacobian(rhs)
    
    Jfun([1,1])
    
  • emma
    emma about 10 years
    strange..i was pretty sure i've tried that before..anyway, it worked! thank you very much - i wish every problem could be solved in one line!
  • Saullo G. P. Castro
    Saullo G. P. Castro about 10 years
    @klim I found out this was the problem based on your error message... since ravel is a method of the ndarray object, it was likely that returning the array instead of the list would solve the problem