Re: [Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Stuart Reynolds
Doh! Thanks for that. On Tue, Nov 15, 2016 at 10:48 AM, Marten van Kerkwijk < m.h.vankerkw...@gmail.com> wrote: > Hi Stuart, > > It certainly seems correct behaviour to return the subclass you > created: after all, you might want to keep the information on > `columns` (e.g., consider doing nanmin

Re: [Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Nathan Goldbaum
You might also want to consider writing a wrapper object that contains an ndarray as a (possibly private) attribute and then presents different views or interpretations of that array. Subclassing ndarray is a pit of snakes, it's best to avoid it if you can (I say as the author and maintainer of an

Re: [Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Marten van Kerkwijk
Hi Stuart, It certainly seems correct behaviour to return the subclass you created: after all, you might want to keep the information on `columns` (e.g., consider doing nanmin along a given axis). Indeed, we certainly want to keep the unit in astropy's Quantity (which also is a subclass of ndarray

[Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Stuart Reynolds
I'm trying to subclass an ndarray so that I can add some additional fields. When I do this however, I get new odd behavior when my object is passed to a variety of numpy functions. For example nanmin returns now return an object of the type of my new array class, whereas previously I'd get a float6

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-02-01 Thread Todd
On Wed, Jan 30, 2013 at 11:20 AM, Sebastian Berg wrote: > > > > > > > > In my particular case at least, there are clear ways to > > handle corner > > > cases (like being passed a class that lacks these > > attributes), so in > > > principle there no problem

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-30 Thread Sebastian Berg
On Wed, 2013-01-30 at 10:24 +0100, Todd wrote: > On Tue, Jan 22, 2013 at 1:44 PM, Sebastian Berg > wrote: > Hey, > > On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > > > > The main exception I have found is concatenate (and > hstack/vstack

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-30 Thread Todd
On Tue, Jan 22, 2013 at 1:44 PM, Sebastian Berg wrote: > Hey, > > On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > > > The main exception I have found is concatenate (and hstack/vstack, > > which just wrap concatenate). In this case, __array_finalize__ is > > passed an array that has already been

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-22 Thread Sebastian Berg
On Tue, 2013-01-22 at 13:44 +0100, Sebastian Berg wrote: > Hey, > > On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > > I am trying to create a subclass of ndarray that has additional > > attributes. These attributes are maintained with most numpy functions > > if __array_finalize__ is used. > >

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-22 Thread Sebastian Berg
Hey, On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > I am trying to create a subclass of ndarray that has additional > attributes. These attributes are maintained with most numpy functions > if __array_finalize__ is used. > You can cover a bit more if you also implement `__array_wrap__`, thou

[Numpy-discussion] Subclassing ndarray with concatenate

2013-01-22 Thread Todd
I am trying to create a subclass of ndarray that has additional attributes. These attributes are maintained with most numpy functions if __array_finalize__ is used. The main exception I have found is concatenate (and hstack/vstack, which just wrap concatenate). In this case, __array_finalize__ i

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Chris Barker
On Tue, May 22, 2012 at 1:07 PM, Dan Goodman wrote: > I think it would be useful to have an example of a completely > 'correctly' subclassed ndarray that handles all of these issues that > people could use as a template when they want to subclass ndarray. I think this is by definition impossible

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Tom Aldcroft
On Tue, May 22, 2012 at 4:07 PM, Dan Goodman wrote: > On 22/05/2012 18:20, Nathaniel Smith wrote: >> I don't know of anything that the docs are lacking in particular. It's >> just that subclassing in general is basically a special form of >> monkey-patching: you have this ecosystem of cooperating

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Dan Goodman
On 22/05/2012 18:20, Nathaniel Smith wrote: > I don't know of anything that the docs are lacking in particular. It's > just that subclassing in general is basically a special form of > monkey-patching: you have this ecosystem of cooperating methods, and > then you're inserting some arbitrary change

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Nathaniel Smith
On Mon, May 21, 2012 at 6:47 PM, Tom Aldcroft wrote: > Over on the scipy-user mailing list there was a question about > subclassing ndarray and I was interested to see two responses that > seemed to imply that subclassing should be avoided. > > >From Dag and Nathaniel, respectively: > > "Subclassi

[Numpy-discussion] subclassing ndarray subtleties??

2012-05-21 Thread Tom Aldcroft
Over on the scipy-user mailing list there was a question about subclassing ndarray and I was interested to see two responses that seemed to imply that subclassing should be avoided. >From Dag and Nathaniel, respectively: "Subclassing ndarray is a very tricky business -- I did it once and regrette

[Numpy-discussion] subclassing ndarray

2011-11-21 Thread Chris.Barker
Hi folks, I'm working on a "ragged array" class -- an array that can store and work with what can be considered tabular data, with the rows of different lengths: """ ragged_array A "ragged" array class -- build on numpy The idea is to be able to store data that is essentially 2-d, but each

[Numpy-discussion] Subclassing ndarray

2011-11-18 Thread Fabrice Silva
Hi, I wish I could subclass ndarray so that I can use the ufuncs, but that I could ensure the array remains Fortran contiguous, and that the number of dimension is always 3 (even if the dtype can be more complex than a simple numerical type). My intention is to deal with fields that can be scalar,

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Pierre GM
On Jul 28, 2010, at 7:52 PM, Pauli Virtanen wrote: > Wed, 28 Jul 2010 18:43:30 -0400, Pierre GM wrote: > [clip] >> Mmh. I did create a PyMappingMethod structure called MyArray_as_mapping, >> and MyArray_as_mapping.mp_subscript points to the function that I want >> to use. However, I'd like the My

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Pauli Virtanen
Wed, 28 Jul 2010 18:43:30 -0400, Pierre GM wrote: [clip] > Mmh. I did create a PyMappingMethod structure called MyArray_as_mapping, > and MyArray_as_mapping.mp_subscript points to the function that I want > to use. However, I'd like the MyArray_as_mapping.length and > MyArray.mp_ass_subscript to po

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Pierre GM
On Jul 28, 2010, at 5:52 PM, Travis Oliphant wrote: > > On Jul 26, 2010, at 11:58 AM, Pierre GM wrote: > >> All, >> I'm teaching myself how to subclass ndarrays in C (not in Cython, just plain >> C). It's slowly coming together, but I'm now running into a problem: I need >> to overwrite __get

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Travis Oliphant
On Jul 26, 2010, at 11:58 AM, Pierre GM wrote: > All, > I'm teaching myself how to subclass ndarrays in C (not in Cython, just plain > C). It's slowly coming together, but I'm now running into a problem: I need > to overwrite __getitem__ and I'm not sure how to do it. I was thinking about > us

[Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-26 Thread Pierre GM
All, I'm teaching myself how to subclass ndarrays in C (not in Cython, just plain C). It's slowly coming together, but I'm now running into a problem: I need to overwrite __getitem__ and I'm not sure how to do it. I was thinking about using my own function instead of array_as_mapping.mp_subscrip

Re: [Numpy-discussion] subclassing ndarray in python3

2010-03-11 Thread Darren Dale
Hi Pauli, On Thu, Mar 11, 2010 at 3:38 PM, Pauli Virtanen wrote: > Thanks for testing. I wish the test suite was more complete (hint! > hint! :) I'll be happy to contribute, but lately I get a few 15-30 minute blocks a week for this kind of work (hence the short attempt to work on Quantities thi

Re: [Numpy-discussion] subclassing ndarray in python3

2010-03-11 Thread Pauli Virtanen
Hi Darren, to, 2010-03-11 kello 11:11 -0500, Darren Dale kirjoitti: > Now that the trunk has some support for python3, I am working on > making Quantities work with python3 as well. I'm running into some > problems related to subclassing ndarray that can be illustrated with a > simple script, repr

[Numpy-discussion] subclassing ndarray in python3

2010-03-11 Thread Darren Dale
Now that the trunk has some support for python3, I am working on making Quantities work with python3 as well. I'm running into some problems related to subclassing ndarray that can be illustrated with a simple script, reproduced below. It looks like there is a problem with the reflected operations,

[Numpy-discussion] subclassing ndarray

2008-12-05 Thread Steve Schmerler
Hi all I'm subclassing ndarray following [1] and I'd like to know if i'm doing it right. My goals are - ndarray subclass MyArray with additional methods - replacement for np.array, np.asarray on module level returning MyArray instances - expose new methods as functions on module level

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-11 Thread Bernhard Voigt
Hi Pierre, that's great! I didn't do exactly what I wanted, but seeing how to overwrite the __getitem__ and __getslice__ methods I can adapt my class that it works with the use cases I need. Thanks for your help! Bernhard On 5/11/07, Pierre GM <[EMAIL PROTECTED]> wrote: Bernhard, Looks like y

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-10 Thread Pierre GM
Bernhard, Looks like you have to modify your __getitem__ and __getslice__ methods. The following seems to work in simple cases. The numpy.array in front of numpy.ndarray.__getxxx__ is to transform the 'numpy.void def __getitem__(self, key): if isinstance(key, arraydict) and key.dtyp

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-10 Thread Bernhard Voigt
Sorry for the spam, but I didn't modify the subject of the previous mail. Here's the message again but now with the right subject: Dear Pierre, I've attached the arraydict implementation file. You can run it and take a look at the following example on your own: In [25]: run arraydict.py create

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-09 Thread Pierre GM
On Wednesday 09 May 2007 08:54:37 Bernhard Voigt wrote: > I'm trying to subclass ndarray or recarray to build a record array that has > a dictionary with a mapping of keys to array indexes and vice versa. Bernhard, Could you send me the rest of your code ? I'd like to test a couple of things bef

[Numpy-discussion] subclassing ndarray and recarray

2007-05-09 Thread Bernhard Voigt
I'm trying to subclass ndarray or recarray to build a record array that has a dictionary with a mapping of keys to array indexes and vice versa. I come across the problem, that depending on the field access method I get different types back: # a is a sublcass of record array print type(a) pr

[Numpy-discussion] Subclassing ndarray in Pyrex

2007-01-31 Thread Pierre GM
I'm still trying to subclass ndarray in Pyrex, without much success so far. I started to follow Francesc's suggestion (http://projects.scipy.org/pipermail/numpy-discussion/2007-January/025644.html), but that doesn't fit what I need: the myarray class Francesc introduced is just an object, not