[Numpy-discussion] linked variables?

Payton Gardner w.gardner@utah....
Tue Jun 3 16:19:10 CDT 2008


Its probably something simple I don't understand but...

I've written a dummy function which takes an array m.  I'd like it to  
return a changed array m_i, and not change the initial array m.  I  
call it with mm = dummy(m);

      3 from numpy import *;
       4 def dummy(m):
       5     m_o = m;
       6     pdb.set_trace();
       7     m_step  = 100;
       8     m_i = m_o;
       9     dummy = m;
      10     dummy2 = m_o;
      11     dummy3 = m_o;
      12     i = 0;
      13     m_i[i] = m_i[i] + m_step;
      14     return(m_i);

But after line 13 m, m_o, dummy, dummy2, and dummy3 are all changed  
by m_step, as well mm which is in a different name space.  All I've  
asked it to do is change m_i.  What's happening?

Thanks,
Payton




Payton Gardner
University of Utah
Department of Geology and Geophysics





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080603/7f539e09/attachment.html 


More information about the Numpy-discussion mailing list