[Numpy-discussion] Please help with subclassing numpy.ndarray
Sturla Molden
sturla@molden...
Tue Feb 6 06:06:37 CST 2007
> def __new__(cls,...)
> ...
> (H, edges) = numpy.histogramdd(..)
> cls.__defaultedges = edges
>
> def __array_finalize__(self, obj):
> if not hasattr(self, 'edges'):
> self.edges = self.__defaultedges
So in order to get an instance attribute, one has to temporarily define it
as a class attribute? What happens if there is a thread switch between
__new__ and __array_finalize__? This design is not thread safe and can
produce strange race conditions.
IMHO, the preferred way to set an instance attribute is to use __init__
method, which is the 'Pythonic' way to do it.
Sturla Molden
More information about the Numpy-discussion
mailing list