From: Stefan v. d. W. <st...@su...> - 2006-10-20 00:19:58
|
On Thu, Oct 19, 2006 at 09:45:02AM -0600, Travis Oliphant wrote: > Stefan van der Walt wrote: >=20 > >If I understand correctly, the following should work: > > > >import numpy as N > > > >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) One has to be careful of this approach. It ads *the same* information to all arrays, i.e. In [2]: a =3D ImageInfo(N.array([1,2,3]),{1:1}) In [3]: b =3D ImageInfo(N.array([1,2,3]),{1:2}) In [4]: a Out[4]: ImageInfo([1, 2, 3]) In [5]: b Out[5]: ImageInfo([1, 2, 3]) In [6]: a.info Out[6]: {1: 2} In [7]: b.info Out[7]: {1: 2} Regards St=E9fan |