[Edu-sig] Properties use case

Michael Tobis mtobis at gmail.com
Thu Mar 16 04:34:13 CET 2006

A Numeric array is mutable; it refers to allocated memory. So any
subpart of it is mutable. So I suggest you use a 1-element complex
numeric array as your mutable complex type.

>>> import Numeric as N
>>> a = N.ones((20,20),N.Complex)
>>> b = N.ravel(a[1:2,1:2])
>>> b
array([ 1.+0.j])
>>> id(b)
>>> b += 1 + 1j
>>> b
array([ 2.+1.j])
>>> id(b)

Admittedly the str() of this object is ugly, and because Numeric isn't
inheritance-friendly this is hard to work around elegantly. If this is
a problem it might provide the occasion to upgrade to a newer
numerical package.

Still, why do you care about mutability of your complex number
instances once they are outside Numeric? That seems unusual.


More information about the Edu-sig mailing list