On 05/31/2011 11:04 AM, Edoardo Pasca wrote: > Dear all, > > sometimes I encounter the problem that calling many times a function > it happens that some local variables are not defined and the procedure > crashes. > > For example I have a function defined as > > def procedure(tt, Ctissue, WeinmannFit, bodyWeight): > for maxFastSampling in range(1,len(tt)): > if tt[maxFastSampling] - tt[maxFastSampling-1]> 10: > break > > if numpy.equal(Ctissue[:maxFastSampling] , 0 ).all(): > # do something > > Now the inputs are all numpy.array except bodyWeight that is a number. > > The program calls the function procedure many times but at some point > fails at the evaluation of numpy.equal with > > UnboundLocalError: local variable 'maxFastSampling' referenced before > assignment > > I wonder whether you see any way that the maxFastSampling variable > might not be set.
Edo, When len(tt) is <2, range(1, len(tt)) gives an emtpy list, the for loop will never execute and maxFastSampling will not be set. VS. > > Python 2.6.4 > numpy 1.5.0 > > Thanks > > Edo > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion