Python Forum
The size of the array returned by func (1) does not match
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The size of the array returned by func (1) does not match
#1
I am new to python, so please bear with me. I am solving a model using odeint function in Python in which I am getting an error: The size of the array returned by func (1) does not match the size of y0 (2)... Maybe I am doing a mistake in returing args in odeint functions. I don't know what is the problem or maybe I am getting the error in wrong direction. Correct me if I am wrong.
from scipy import *
from scipy.integrate import odeint
from operator import itemgetter
import matplotlib
matplotlib.use('Agg')
from matplotlib.ticker import FormatStrFormatter
from pylab import *

import sys

ExpData = [1.0 , 1.1660520579009868 , 1.3688685188071037 , 1.6165891026469563 ,
           1.9191557810726714 ]

t_range = arange(0.0,20.0,0.1)

initial_condi = [1,0.5]
VarList = ["a","b"]
ParaList = ["k1","k2"]
k1 = 1
k2 = 2

if len(initial_condi)!=len(VarList):
    sys.exit('error')

def odeFunc(Y,t,modelID,t1,t2):
    return GenModel(Y,modelID,t1,t2)

def GenModel(Y,modelID,t1,t2):
    RetY = [None]
    if modelID == 1:
        RetY = Y[0] + Y[1]
    elif modelID == 2:
        RetY = t1*Y[0] + Y[1]
    elif modelID == 3:
        RetY = Y[0] + t1*Y[1]


    if Y[0] == 0 or Y[1] == 0:
        if modelID == 27:
            RetY = 0
        elif modelID == 28:
            RetY = 0
    if Y[0] != 0 and Y[1] != 0:
        if modelID == 27:
            RetY = Y[0]*Y[1]
        elif modelID ==28:
            RetY = t1*Y[0]*Y[1]
        elif modelID == 29:
            RetY = t2*Y[0]*Y[1]

    return RetY

def EvalModelFitness(Stofloat,ExpData):
    Sum = 0.0
    for i in range(len(Stofloat)):
        Sum += (Stofloat[i]-ExpData[i])**2
    print Sum/len(Stofloat)
    
if initial_condi[0] == 0 or initial_condi[1] == 0:
    NumModels = 28
else:
    NumModels = 39

for j in range(1,NumModels+1):
    S = odeint(odeFunc, initial_condi,t_range,args=(j,k1,k2))
    Stofloat = S[:,0].astype(type('float',(float,),{}))
    EvalModelFitness(Stofloat,ExpData)

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cannot reshape array of size 0 into shape Roro 2 1,078 Jun-14-2020, 11:28 AM
Last Post: Roro
  How to get the size of a numpy array? mcgrim 2 867 Mar-23-2019, 02:25 PM
Last Post: perfringo
  python odeint keeps giving me size of array error kiyoshi7 1 1,692 Nov-01-2018, 02:03 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020