[Tutor] passing global variable as argument.

Bala subramanian bala.biophysics at gmail.com
Mon Jul 16 13:00:40 CEST 2012


Friends,
I want to define a function that can populate an array by taking its name
(which is defined globally). I defined two empty arrays as follows and a
function that can populate the array.

REF_F1=np.array([])
REF_F2=np.array([])

# populating the given array
def ref(ln,REF_F1):
    global REF_F1
    REF_F1=np.zeros((ln,3),dtype='float32')
    for i in range(ln):
        for j in range(3):
           REF_F1x[i,j]=resid[Index[i]].cent()[j]

ref(ln, REF_F2)

In this case, when i pass REF_F2 as argument, the fn. always populates
array REF_F1. I also tried something like the following
*def ref(ln,x=REF_F1)* and then calling as *ref(ln,x=REF_F2)*. The result
is the same. Could someone please give me hint on how pass global variables
as arguments.

Thanks,
Bala








-- 
C. Balasubramanian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120716/89337a9f/attachment.html>


More information about the Tutor mailing list