[SciPy-User] How to feed np.mgrid a variable number of 'arguments'

Robert Kern robert.kern@gmail....
Mon Mar 5 12:36:53 CST 2012


On Mon, Mar 5, 2012 at 18:27, Collin Day <dcday137@gmail.com> wrote:
> Hi all,
>
> I am guessing there is an easy way to do this, but I am just not seeing it.
> I have a function where I can have a variable number of input dimensions.
> In the function, I need to use np.mgrid to generate the data I need.  How
> would I create a line of code that would feed np.mgrid a variable number of
> inputs?  For example:
>
> 3d, with 17 nodes
>
> a = np.mgrid[0:17,0:17,0:17]
>
> 4d
>
> a = np.mgrid[0:17,0:17,0:17,0:17]
>
> Is there a way I can do
>
> nodes=17
> inDims = a_number
>
> a = np.mgrid[0:17,0:17...a_number of times]
>
> easily?

ix = (slice(0, nodes),) * inDims
a = np.mgrid[idx]

-- 
Robert Kern


More information about the SciPy-User mailing list