[Numpy-discussion] Using new numeric instances in NumArray and RecArray.

Sebastian Haase haase at msg.ucsf.edu
Mon Dec 13 09:10:01 EST 2004

Hi Ivan,
I might be ignorant because if have never heard about the 
"same-but-distinguishable" concept (except from general oo-deriving of 
course). But I might actually have a similar situation.
I have a 3d-image file-format which I wanted to handle mostly just by it's 
pixel-data content, that is: I return it as numarray.
But to allow me to access the extra (header) information that comes with that 
file-format I "stick" a new attribute into the numarray instance. (this must 
sound very surprising to e.g. C++-people put is standard python as I 
So here is some outline of my code:
class Mrc: # our "mrc"-file-format
    def __init__(self):
        open-file, make memmap for header+ data
        data.Mrc = self  # this is the "sticking-in part"
        return data
This is very much paraphrased. I think __init__ doesn't have a return (so I 
use a seprarate function for that). And (after much debugging) I now use 
"weakref" for the "sticking-in part" to avoid circular references.

Tell me if I guessed you case right (at least somewhat) ;-)

Sebastian Haase

On Monday 13 December 2004 08:48 am, Todd Miller wrote:
> On Mon, 2004-12-13 at 11:23, Ivan Vilata i Balaguer wrote:
> >   I'm trying to define new types that can be handled as normal types in
> >   numarray, but being different (distinguishable) from their equivalent
> >   types.  For instance, an array of MyInt32 should work exactly as an
> >   Int32 array, but I would need to know it is a MyInt32 array and not an
> >   Int32 one.
> >
> >       However, I you believe that the system is not prepared for that
> >   (or it would require too much work) I will try to identify it by some
> >   external means.  Thank you anyway for your prompt answer.
> I think the system is simply not designed for that.  For what you want,
> I think Int32 would need to be a class, not an instance, so that it
> could be subclassed while retaining a relatively simple C
> implementation.  As you noted,  the C infrastructure works using a type
> mapping table which maps type *instances* onto type numbers, so it won't
> work as it is now.
> Regards,
> Todd
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list