[Numpy-discussion] local variable referenced before assignment

Edoardo Pasca edo.paskino at gmail.com
Tue May 31 05:04:38 EDT 2011

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

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:

    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.

Python 2.6.4
numpy 1.5.0



weblog  http://edo.imanetti.net/wordpress
podcast http://sieegiueeaccaso.blogspot.com
cooking http://edo.imanetti.net/cucina

More information about the NumPy-Discussion mailing list