[NumPy-Tickets] [NumPy] #966: Enhance meshgrid to generate 3D grids + add option for sparse grids

NumPy Trac numpy-tickets@scipy....
Thu Dec 22 07:02:16 CST 2011


#966: Enhance meshgrid  to generate 3D grids + add option for sparse grids
-------------------------+--------------------------------------------------
 Reporter:  pbrod        |       Owner:  charris     
     Type:  enhancement  |      Status:  needs_review
 Priority:  normal       |   Milestone:  Unscheduled 
Component:  numpy.lib    |     Version:  devel       
 Keywords:  meshgrid     |  
-------------------------+--------------------------------------------------

Comment(by pbrod):

 I have 2 comments to https://github.com/rgommers/numpy/tree/meshgrid3d.
 The first one relates to cartesian indexing for ndim>2:
 In Matlab the meshgrid function only accepts up to three inputs and it
 always return the variables with a cartesian indexing scheme (i.e., where
 the 2 first dimensions are  switched). For ndim>3 in matlab you must use
 the ndgrid function, which returns the variables with a matrix indexing
 scheme.
 One could switch to matrix indexing if ndim>3, but I think that will be
 even more confusing.  Another option is to do like Matlab:
 * restrict ndim to 3 for meshgrid and always return cartesian indexing.
 * have a separate ndgrid function (with no restrictions on ndim) that
 always returns arrays with a matrix indexing scheme

 This is both simpler and more explicit. However, a third option is to
 leave it as it is if adding ndgrid is too much.

 The second comment is about removing the test for "input as list"
 Removing the the test for the "input as list" in
 https://github.com/rgommers/numpy/tree/meshgrid3d
 have the effect that a single input array is interpreted as
 multidimensional input as shown in the following example:

 {{{
 In [21]: x = np.array([1,2])
 In [22]: meshgrid(x)
 Out[22]: [array([[1]]), array([[2]])]
 }}}
 gives the same as
 {{{
 In [23]: meshgrid(x[0],x[1])
 Out[23]: [array([[1]]), array([[2]])]
 }}}
 Is this a wanted feature for meshgrid?
 I think this is confusing. I would expect meshgrid(x) to raise an error
 message in this situation just like the call to meshgrid(1) does.


 {{{
 In [24]: meshgrid(x,x)
 Out[24]:
 [array([[1, 2],
        [1, 2]]), array([[1, 1],
        [2, 2]])]

 In [25]: y = 1

 In [26]: meshgrid(y)
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)

 C:\Documents and Settings\pab\.xy\startups\<ipython console> in <module>()

 C:\Documents and Settings\pab\.xy\startups\<string> in meshgrid(*xi,
 **kwargs)

 TypeError: meshgrid() takes 2 or more arguments (1 given)

 In [27]: meshgrid(y,y)
 Out[27]: [array([[1]]), array([[1]])]
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/966#comment:11>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list