Meshgrid enhancements (>2-D, sparse grids, matrix indexing) #192

Merged
merged 5 commits into from Jul 18, 2012

Conversation

Projects
None yet
5 participants
numpy/lib/function_base.py
+ If False, a view into the original arrays are returned in
+ order to conserve memory. Default is True. Please note that
+ ``sparse=False, copy=False`` will likely return non-contiguous arrays.
+ Furthermore, more than one element of a broadcasted array may refer to

This comment has been minimized.

@charris

charris Feb 1, 2012

Member

broadcast, not broadcasted. Although languages do evolve ;)

@charris

charris Feb 1, 2012

Member

broadcast, not broadcasted. Although languages do evolve ;)

This comment has been minimized.

@rgommers

rgommers Feb 5, 2012

Member

fixed

@rgommers

rgommers Feb 5, 2012

Member

fixed

+ This function supports both indexing conventions through the indexing keyword
+ argument. Giving the string 'ij' returns a meshgrid with matrix indexing,
+ while 'xy' returns a meshgrid with Cartesian indexing. In the 2-D case
+ with inputs of length M and N, the outputs are of shape (N, M) for 'xy'

This comment has been minimized.

@charris

charris Feb 1, 2012

Member

Maybe explain this with a connection to image plots, where the 'x' typically runs left to right and is the 'fast' index. Or is that what this is about. Where would one use 'ij' ?

@charris

charris Feb 1, 2012

Member

Maybe explain this with a connection to image plots, where the 'x' typically runs left to right and is the 'fast' index. Or is that what this is about. Where would one use 'ij' ?

This comment has been minimized.

@teoliphant

teoliphant Feb 1, 2012

Member

I agree. I find the "matrix indexing" versus "Cartesian indexing" description hard to understand. I think you are talking about "image" conventions versus "plotting" conventions. Is that correct?

@teoliphant

teoliphant Feb 1, 2012

Member

I agree. I find the "matrix indexing" versus "Cartesian indexing" description hard to understand. I think you are talking about "image" conventions versus "plotting" conventions. Is that correct?

This comment has been minimized.

@rgommers

rgommers Feb 5, 2012

Member

Correct, image convention vs. just standard array/matrix indexing. Since this is the most confusing part apparently (see also discussion on this point at http://projects.scipy.org/numpy/ticket/966), I'm tempted to just leave out the indexing keyword after all. This seems to be confusing for Matlab users too, see for example the comments at http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/.

There really isn't an ideal solution here.

Note that mgrid and ogrid use 'ij', while currently meshgrid uses 'xy':

In [35]: mgrid[0:2, 3:5]
Out[35]: 
array([[[0, 0],
        [1, 1]],

       [[3, 4],
        [3, 4]]])

In [36]: meshgrid([0, 1], [3, 4])
Out[36]: 
[array([[0, 1],
       [0, 1]]), array([[3, 3],
       [4, 4]])]
@rgommers

rgommers Feb 5, 2012

Member

Correct, image convention vs. just standard array/matrix indexing. Since this is the most confusing part apparently (see also discussion on this point at http://projects.scipy.org/numpy/ticket/966), I'm tempted to just leave out the indexing keyword after all. This seems to be confusing for Matlab users too, see for example the comments at http://blogs.mathworks.com/loren/2007/06/21/indexing-terminology/.

There really isn't an ideal solution here.

Note that mgrid and ogrid use 'ij', while currently meshgrid uses 'xy':

In [35]: mgrid[0:2, 3:5]
Out[35]: 
array([[[0, 0],
        [1, 1]],

       [[3, 4],
        [3, 4]]])

In [36]: meshgrid([0, 1], [3, 4])
Out[36]: 
[array([[0, 1],
       [0, 1]]), array([[3, 3],
       [4, 4]])]

This comment has been minimized.

@charris

charris Feb 5, 2012

Member

Maybe call ir 'image' indexing? I find in practice it is easier to settle on a single convention ('ij'), always put x in the first index, and just transpose for showing images. Mixing the conventions leads to all sorts of confusion.

@charris

charris Feb 5, 2012

Member

Maybe call ir 'image' indexing? I find in practice it is easier to settle on a single convention ('ij'), always put x in the first index, and just transpose for showing images. Mixing the conventions leads to all sorts of confusion.

This comment has been minimized.

@rgommers

rgommers Feb 5, 2012

Member

Only using 'ij' would be best probably, but since currently meshgrid uses 'xy' we can't do that.

@rgommers

rgommers Feb 5, 2012

Member

Only using 'ij' would be best probably, but since currently meshgrid uses 'xy' we can't do that.

This comment has been minimized.

@charris

charris Feb 5, 2012

Member

Oops, see, I already got confused ;) I think a different choice of names would clarify things, 'xy' seems ok, 'standard' would be another option, and then maybe 'image' for the second choice, with a short explanation (images are displayed left-right, top-bottom) and a translation for Matlab users.

@charris

charris Feb 5, 2012

Member

Oops, see, I already got confused ;) I think a different choice of names would clarify things, 'xy' seems ok, 'standard' would be another option, and then maybe 'image' for the second choice, with a short explanation (images are displayed left-right, top-bottom) and a translation for Matlab users.

This comment has been minimized.

@rgommers

rgommers May 28, 2012

Member

ij --> image sounds OK to me. Although I forgot the details by now. With added explanation it should work.

@rgommers

rgommers May 28, 2012

Member

ij --> image sounds OK to me. Although I forgot the details by now. With added explanation it should work.

+ output[0].shape = (1, -1) + (1,)*(ndim - 2)
+ output[1].shape = (-1, 1) + (1,)*(ndim - 2)
+ shape[0], shape[1] = shape[1], shape[0]
+

This comment has been minimized.

@charris

charris Feb 1, 2012

Member

So 'xy' indexing only affects the first two axis?

@charris

charris Feb 1, 2012

Member

So 'xy' indexing only affects the first two axis?

This comment has been minimized.

@rgommers

rgommers Feb 5, 2012

Member

yes

numpy/lib/tests/test_function_base.py
+ [5],
+ [6],
+ [7]])))
+

This comment has been minimized.

@charris

charris Feb 1, 2012

Member

Any reason not to put that on a single line?

@charris

charris Feb 1, 2012

Member

Any reason not to put that on a single line?

This comment has been minimized.

@rgommers

rgommers Feb 5, 2012

Member

not really, changed that now.

@rgommers

rgommers Feb 5, 2012

Member

not really, changed that now.

@teoliphant

This comment has been minimized.

Show comment
Hide comment
@teoliphant

teoliphant May 28, 2012

Member

It seems that this PR can be merged. Confusion in the naming can be improved later (and already exists between the default mgrid and meshgrid conventions).

Member

teoliphant commented May 28, 2012

It seems that this PR can be merged. Confusion in the naming can be improved later (and already exists between the default mgrid and meshgrid conventions).

@rgommers

This comment has been minimized.

Show comment
Hide comment
@rgommers

rgommers May 28, 2012

Member

Would be better to fix it before/when merging imho, otherwise it will simply be forgotten. Sorry I haven't made the time to finish this off yet.

Member

rgommers commented May 28, 2012

Would be better to fix it before/when merging imho, otherwise it will simply be forgotten. Sorry I haven't made the time to finish this off yet.

@lukecampbell

This comment has been minimized.

Show comment
Hide comment
@lukecampbell

lukecampbell Jul 5, 2012

Looks really good, can't wait for this to be merged.

Looks really good, can't wait for this to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment