From: Stefan v. d. W. <st...@su...> - 2006-10-20 08:47:42
|
On Thu, Oct 19, 2006 at 09:03:57PM -0400, Pierre GM wrote: > Indeed. That's basically why you have to edit your __array_finalize__ . >=20 > class InfoArray(N.ndarray): > def __new__(info_arr_cls,arr,info=3D{}): > info_arr_cls._info =3D info > return N.array(arr).view(info_arr_cls) > def __array_finalize__(self, obj): > if hasattr(obj,'info'): > self.info =3D obj.info > else: > self.info =3D self._info > return >=20 > OK, so you end up w/ two attributes 'info' and '_info', the latter havi= ng the=20 > info you want, the latter playing a temporary placeholder. That looks a= bit=20 > overkill, but that works pretty nice. Is there any reason why one can't simply do class InfoArray(N.ndarray): def __new__(info_arr_cls,arr,info=3D{}): x =3D N.array(arr).view(info_arr_cls) x.info =3D info return x def __array_finalize__(self, obj): if hasattr(obj,'info'): self.info =3D obj.info return Regards St=E9fan |