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

David M. Kaplan David.Kaplan@ird...
Fri Aug 15 09:54:24 CDT 2008


Hi,

A while back, I sent some changes to index_tricks.py that would allow
mgrid and ogrid to mesh things other than slices.  For example:

>>> mgrid[['a','b'],[float,int],:3]
[array([[['a', 'a', 'a'],
        ['a', 'a', 'a']],

       [['b', 'b', 'b'],
        ['b', 'b', 'b']]], 
      dtype='|S1'), array([[[<type 'float'>, <type 'float'>, <type 'float'>],
        [<type 'int'>, <type 'int'>, <type 'int'>]],

       [[<type 'float'>, <type 'float'>, <type 'float'>],
        [<type 'int'>, <type 'int'>, <type 'int'>]]], dtype=object), array([[[0, 1, 2],
        [0, 1, 2]],

       [[0, 1, 2],
        [0, 1, 2]]])]

At the time, there wasn't much follow-up, but I am hoping that there is
still interest in this functionality, as I have gone ahead and finished
the patch including documentation changes and updates to
test_index_tricks.py.  Attached is a patch set to the latest subversion
of the numpy trunk.  I don't think I am allowed to commit the changes
myself - correct me if I am wrong. 

This functionality seems like a nice addition to me as it allows one to
mesh things that are not uniformly spaced and potentially not even
numbers.  The changes don't affect functionality that existed previously
except for one minor change - instead of returning a numpy array of
arrays, mgrid/ogrid now return a list of arrays.  However, this is
unlikely to be a problem as the majority of users generally unpack the
results of mgrid/ogrid so that each matrix can be used individually.

Comments welcome.

Cheers,
David

-- 
**********************************
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
France

Phone: +33 (0)4 99 57 32 27
Fax: +33 (0)4 99 57 32 95
http://www.ur097.ird.fr/team/dkaplan/index.html
**********************************

-------------- next part --------------
A non-text attachment was scrubbed...
Name: index_tricks.patch
Type: text/x-patch
Size: 8077 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080815/cbac9a5c/attachment.bin 


More information about the Numpy-discussion mailing list