Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'float': 0.05; 'method.': 0.05; 'array.': 0.07; 'cc:addr:python-list': 0.09; 'integration,': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'subject:using': 0.09; 'throws': 0.09; 'typeerror:': 0.09; 'python': 0.10; 'variables': 0.15; '#this': 0.16; 'arrays.': 0.16; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'constants': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'function).': 0.16; 'message- id:@fido.openend.se': 0.16; 'numpy': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'solver.': 0.16; 'steps,': 0.16; 'subject:Integration': 0.16; 'tran': 0.16; 'unequal': 0.16; 'laura': 0.18; 'runs': 0.18; 'changes': 0.20; '2015': 0.20; 'cc:addr:python.org': 0.20; '(the': 0.22; 'cc:2**1': 0.22; 'saying': 0.22; 'arrays': 0.22; 'converted': 0.22; 'function,': 0.22; 'sep': 0.22; 'pass': 0.22; 'code,': 0.23; 'dependent': 0.23; 'errors': 0.23; 'passing': 0.23; 'skip:( 40': 0.23; 'tried': 0.24; "i've": 0.25; 'error': 0.27; 'defining': 0.27; 'function': 0.28; 'values': 0.28; 'skip:( 20': 0.28; 'initial': 0.28; '-0700,': 0.29; 'integrating': 0.29; 'loop,': 0.29; 'received:se': 0.29; 'array': 0.29; 'cc:no real name:2**1': 0.29; "i'm": 0.30; 'code': 0.30; 'another': 0.32; 'says': 0.32; 'getting': 0.33; 'problem': 0.33; 'call,': 0.33; 'skip:( 30': 0.35; 'something': 0.35; 'problem.': 0.35; 'according': 0.36; 'but': 0.36; 'instead': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'charset:us-ascii': 0.37; 'list.': 0.37; 'wanted': 0.37; 'anything': 0.38; 'where': 0.40; 'header:Message-Id:1': 0.61; 'you.': 0.64; 'respect': 0.65; 'here': 0.66; 'experts': 0.70; 'integrated': 0.72; '>def': 0.84; '>if': 0.84; 'header:In-reply-to:1': 0.84; 'temperature': 0.84 To: sagar k cc: python-list@python.org, lac@openend.se From: Laura Creighton Subject: Re: Integration using scipy odeint In-reply-to: References: Comments: In-reply-to sagar k message dated "Sun, 13 Sep 2015 07:49:37 -0700." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28763.1442168643.1@fido> Content-Transfer-Encoding: quoted-printable Date: Sun, 13 Sep 2015 20:24:03 +0200 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [82.96.5.2]); Sun, 13 Sep 2015 20:24:06 +0200 (CEST) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442168654 news.xs4all.nl 23851 [2001:888:2000:d::a6]:32862 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96516 In a message of Sun, 13 Sep 2015 07:49:37 -0700, sagar k writes: >Dear all = > >I'm using Python 3.4.3. I am facing a problem in integrating using odeint= solver. In the following code, tran is a function and in those are the va= riables which are arrays. These variables change their values with respect= to time (the time which I pass to the function). I tried defining a loop = inside the function, but Python throws an error saying float object not it= erable. Please guide me how to solve this problem. = > >#initial is an array containing initial values for the integration, dt is= the time array with unequal time steps, which I have captured from other = part of the code > >def tran(initial,dt): > for i in dt: > k1 [i] =3D 2.8e8 * math.exp(-21100/ta[i]) # k1,k2,k3 & k4 are con= stants which change according to temperature (ta), which in turn changes w= ith respect to time. = > k2 [i] =3D 1.4e2 * math.exp(-12100/ta[i]) # ta changes its values= according to dt, which is array. It runs from 0-6 with unequal time steps= . > k3 [i] =3D 1.4e5 * ta[i] * math.exp(-19680/ta[i]) # I've captured= dt and all other arrays here from another loop, which is not of importtan= ce. > k4 [i] =3D 1.484e3 * ta[i] > y =3D initial[0] > z =3D initial[1] > dn =3D (6*rho*initial[1]) > dd =3D (math.pi*2000*initial[0]) > ds =3D (dn/dd)**1/3 > dydt =3D (166.2072*ta[i]*cca[i] - (1.447e13 * ta[i]**0.5 * rho**1= /6 * y**1/6 * rho**1/6 * z**1/6 * 0.0832)) # cca,ta are arrays. y & z are = 2 dependent variables > dzdt =3D (k1[i]*ta[i]*cca[i]*12.011 + (21.2834*k2[i]*ta[i]*cca[i]= * y**1/2 *ds) - (k3[i]*ta[i]*12.011*y*math.pi*ds**2 * cco[i]) - > (phi*k4[i]*ta[i]*xo[i]*12.011*y*math.pi*ds**2)) >return [dydt,dzdt] # dydt & dzdt are my final time integrated values > >initial =3D [0.01,1e-5] >sol =3D odeint(tran, initial, dt) #this is my function call > >If I pass array in my function call, it says only length-1 can be convert= ed to Python scalars. > >So I request all the experts in the group to tell me where I'm going wron= g. > >Regards You are getting this error, correct? TypeError: only length-1 arrays can be converted to Python scalars I don't know anything about odeint. But when I get these errors it is because I passed a numpy array into something that wanted a python list. This may be what you are doing. numpy arrays have a tolist method. see if passing array.tolist() instead of array works for you. Laura