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

Chris Weisiger cweisiger at msg.ucsf.edu
Mon Mar 5 13:36:25 EST 2012


On Mon, Mar 5, 2012 at 10:27 AM, Collin Day <dcday137 at gmail.com> wrote:
> Is there a way I can do
>
> a = np.mgrid[0:17,0:17...a_number of times]

You want the slice() function. For example:

slices = []
for i in xrange(num_times):
    slices.append(slice(0, 17))
a = np.mgrid[slices]

-Chris



More information about the SciPy-User mailing list