[Numpy-discussion] New patch for new mgrid / ogrid functionality

David Kaplan David.Kaplan@ird...
Wed Sep 24 02:57:13 CDT 2008


On Tue, 2008-09-23 at 20:54 -0500, numpy-discussion-request@scipy.org
> On Tue, Sep 23, 2008 at 09:39:53AM +0200, David Kaplan wrote:
> > I would note that there is nothing in the API breakage that prevents
> > doing what Gael mentions.  The only change is that:
> > > > X = mgrid[0:4, 0:4, 0:4]
> > would be replaced with:
> > X = asarray( mgrid[ 0:4, 0:4, 0:4 ] )
> Doesn't this force a data copy?

I am not sure if this forces a copy (asarray shouldn't for arrays,
unlike array, but I am not sure what it does for lists that can
trivially become arrays), but if it does, you are getting it one way or
another - in the non-API-breakage patch I sent, the asarray is
incorporated into the class method itself.

For Robert, the use cases I was talking about included ogrid - ogrid
with or without non-slice arguments always returns a list, mgrid with
non-slices returns a list, but mgrid with all slices returns an array.
I find this funky, but I guess I am going upwind.

I personally find adding another object that does stuff like mgrid and
ogrid, but not exactly the same, hard to swallow.  mgrid and ogrid are
already pretty mysterious, adding another is going to make things worse.
I was initially trying to make things easier for the new user by
providing one function that does all of what you want in a transparent
way; this solution seems to be going in the opposite direction.  If you
do end up adding one, I would call it ndgrid as this is what the matlab
equivalent is called.

The idea of making it a function eliminates the use of slices, which is
where the real power of nd_grid comes in, so I would not go that route.
If you want to go with a new object, I would add a "force_array" option
to nd_grid that would be checked before executing the asarray code -
this option would be true for mgrid, but false for ogrid and "ndgrid".


> Ga?l
David M. Kaplan
Charge de Recherche 1
Institut de Recherche pour le Developpement
Centre de Recherche Halieutique Mediterraneenne et Tropicale
av. Jean Monnet
B.P. 171
34203 Sete cedex

Phone: +33 (0)4 99 57 32 27
Fax: +33 (0)4 99 57 32 95

More information about the Numpy-discussion mailing list