How to fix the error: The array return by func must be one-dimensional, but got ndim=2

前端 未结 2 654
闹比i
闹比i 2021-01-25 20:54

Here is my code:

import numpy as np
from scipy.integrate import odeint
import math

y0=np.array([1,3,2,3,5])
b=np.array([[1],[3],[4],[2],[5]])

\'\'\'generate ma         


        
相关标签:
2条回答
  • 2021-01-25 21:14

    Try changing the order of the arguments of your function to def g(y,t,B). That made the error message go away. You'll want to verify that the math is doing what you expect.

    The documentation of odeint says, "The first two arguments of f(t, y, ...) are in the opposite order..."

    0 讨论(0)
  • 2021-01-25 21:14

    The output array from the function depends on what is the input.

    To ensure that your initial condition is 1-dimensional, you can reshape the y0 array.

    y0_reshaped = y0.reshape(n,)

    where n is the number of elements in your y0 vector

    0 讨论(0)
提交回复
热议问题