On Friday 27 October 2006 18:37, Albert Strasheim wrote:
> Hello all
...
> I would like to create an "info" array like this to attach some metadata,
> mostly sampling frequency, to some of my arrays.
>
...
> I browsed through the NumPy book and looked at the __new__ and
> __array_finalize__ stuff i
Hello all
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:numpy-
> [EMAIL PROTECTED] On Behalf Of Travis Oliphant
> Sent: Thursday, October 19, 2006 5:45 PM
> To: Discussion of Numerical Python
> Subject: Re: [Numpy-discussion] adding an attribute to an nd-array
&
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__ .
>
> class InfoArray(N.ndarray):
> def __new__(info_arr_cls,arr,info={}):
> info_arr_cls._info = info
> return N.array(arr).view(info_arr_cls)
>
> > >class InfoArray(N.ndarray):
> > >def __new__(info_arr_cls,arr,info={}):
> > >info_arr_cls.info = 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.
Indeed. That's basically why
On Thu, Oct 19, 2006 at 09:45:02AM -0600, Travis Oliphant wrote:
> Stefan van der Walt wrote:
>
> >If I understand correctly, the following should work:
> >
> >import numpy as N
> >
> >class InfoArray(N.ndarray):
> >def __new__(info_arr_cls,arr,info={}):
> >info_arr_cls.info = info
> >
On Thu, Oct 19, 2006 at 01:59:49PM -0700, Christopher Barker wrote:
> Travis Oliphant wrote:
> > Actually something as simple as
> >
> > class InfoArray(N.ndarray):
> > pass
> >
> > will allow you to add attributes to InfoArray.
>
> Well, sure, but how the heck do you initialize it?
Lo
Christopher Barker wrote:
>Travis Oliphant wrote:
>
>
>>Actually something as simple as
>>
>>class InfoArray(N.ndarray):
>> pass
>>
>>will allow you to add attributes to InfoArray.
>>
>>
>
>Well, sure, but how the heck do you initialize it?
>
>
You use the same constructor as ndarr
Christopher Barker wrote:
> Travis Oliphant wrote:
>
>> Actually something as simple as
>>
>> class InfoArray(N.ndarray):
>> pass
>>
>> will allow you to add attributes to InfoArray.
>>
>
> Well, sure, but how the heck do you initialize it?
>
> >>> class InfoArray(N.ndarray):
> ..
Travis Oliphant wrote:
> Actually something as simple as
>
> class InfoArray(N.ndarray):
> pass
>
> will allow you to add attributes to InfoArray.
Well, sure, but how the heck do you initialize it?
>>> class InfoArray(N.ndarray):
... pass
...
>>> InfoArray((1,2,3))
InfoArray
On 10/19/06, Robert Kern <[EMAIL PROTECTED]> wrote:
> Travis Oliphant wrote:
> > I don't think the extra bytes for every ndarray object are worth it,
> > given how easy it is to sub-class and create your own ndarray that can
> > have attributes attached.What are others opinions.
>
> I'd say lea
Travis Oliphant wrote:
> I just learned about how to allow built-ins to have attributes assigned
> to their instances. It's actually pretty easy because of Python
> support for it --- but it comes at a cost. You have to add a dictionary
> to the PyArrayObject structure, create that dictionary
On 10/19/06, Travis Oliphant <[EMAIL PROTECTED]> wrote:
Stefan van der Walt wrote:>On Wed, Oct 18, 2006 at 09:17:49PM -0400, Pierre GM wrote:On Wednesday 18 October 2006 20:29, Stefan van der Walt wrote:>>
I don't think the extra bytes for every ndarray object are worth it,given how easy it is
Stefan van der Walt wrote:
>On Wed, Oct 18, 2006 at 09:17:49PM -0400, Pierre GM wrote:
>
>
>>On Wednesday 18 October 2006 20:29, Stefan van der Walt wrote:
>>
>>
>>>A quick question on extending numpy arrays: is it possible to easily
>>>add an attribute to an ndarray?
>>>
>>>
>>It migh
Stefan van der Walt wrote:
> On Wed, Oct 18, 2006 at 09:17:49PM -0400, Pierre GM wrote:
>
>> On Wednesday 18 October 2006 20:29, Stefan van der Walt wrote:
>>
>>> A quick question on extending numpy arrays: is it possible to easily
>>> add an attribute to an ndarray?
>>>
>> It might
On Wed, Oct 18, 2006 at 09:17:49PM -0400, Pierre GM wrote:
> On Wednesday 18 October 2006 20:29, Stefan van der Walt wrote:
> > A quick question on extending numpy arrays: is it possible to easily
> > add an attribute to an ndarray?
>
> It might be easier to create a subclass: pleasehave a look he
On Wednesday 18 October 2006 20:29, Stefan van der Walt wrote:
> A quick question on extending numpy arrays: is it possible to easily
> add an attribute to an ndarray?
It might be easier to create a subclass: pleasehave a look here:
http://projects.scipy.org/scipy/numpy/attachment/wiki/MaskedArray
A quick question on extending numpy arrays: is it possible to easily
add an attribute to an ndarray?
With Python-defined classes one can do
class X(object):
pass
x = X()
x.foo = 'bar'
but with ndarrays you get
x = N.array([1,2,3])
x.foo = 'bar'
AttributeError: 'numpy.ndarray' object has n
17 matches
Mail list logo