[Numpy-discussion] use of concatenate with subclass of ndarray
Pierre GM
pgmdevlist at gmail.com
Wed Mar 28 13:25:53 EDT 2007
On Wednesday 28 March 2007 12:42:52 Bryce Hendrix wrote:
> Thanks Pierre, works like a charm. One question though, how is defining
> a class attribute in __new__ any more thread-safe?
It's not, of course, and that's why it shouldn't be used. However, it's quite
convenient and easier to use, and do you really need thread-safe objects ?
In your example, if "yourdefaultunit" takes some simple value, you could use
that value directly instead of the class attributes, which could be slightly
messier to read but definitely thread-safe.
The second aspect about initialization is that when a ndarray is viewed as one
of its subclasses, the actual memory space has already been allocated, so
there's no call to __new__. Instead, you have to rely on __array_finalize__
to initialize the attributes specific to your subclass.
More information about the NumPy-Discussion
mailing list