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

Chris Weisiger cweisiger@msg.ucsf....
Mon Mar 5 12:36:25 CST 2012


On Mon, Mar 5, 2012 at 10:27 AM, Collin Day <dcday137@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