![]() ![]() Those constants will probably change but I do need to input some stuff into dS, dI, dR, and dD that look like deltad and was hoping that someone on here with more python experience could help me. Then I try to plot S, I, R, and D but that error pops up regarding the odeint line. The ValueError: setting an array element with a sequence occurs when: An array does not have a proper shape, i.e. Ret = odeint(deriv, y0, t, args=(alpha, gamma, rho)) S, I, R, D = ret.T # define the constants N = 3.295e8 # population of the US theta = 0.8 # infectiousness zeta = 0.75 # susceptibility c = (N * 10 ** -5) / N # contact rate, depending on percentage of total population alpha = theta * zeta * c gamma = 0.1 # recovery rate, used often in class rho = 0.2 # rate of loss of immunity deltad = 0.1*vd(t) # rate of loss of Vitamin-D in body # these are all the differential equations from simple SIR model def deriv(y, t, alpha, gamma, rho): S, I, R, D = y dS = -alpha * I * S + rho * R dI = alpha * I * S - gamma * I dR = gamma * I - rho * R - rho * R * deltad dD = deltad * (rho * R - S * L(t)) return dS, dI, dR, dD # define some more initial conditions for integration I0 = 1 # 1st person infected R0 = 0 # 0 people recovered at first, obviously S0 = N - I0 - R0 D0 = 0 # initial vitamin D in population, t=0 means January 1st # initial conditions vector y0 = S0, I0, R0, D0 Tmax = 2 * 365 # how long to run the system in days t = np.arange(0.0, tmax, 1.0) ![]() Import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def vd(t): return -(267 / 1440) * np.cos((2 * np.pi) / 365 * t) + (639 / 1440) I also posted this to r/learningpython but this sub seems like it may be more helpful! While testing the code, I keep getting the above value error. Example: import numpy as np print(np. Solution 1: Using Proper Array Dimensions Consider the following example where we have a certain NumPy array with dimensions as shown below. I'm trying to integrate some ordinary differential equations but I need some of the parameters to be a cosine function of time. ValueError: setting an array element with a sequence.
0 Comments
Leave a Reply. |