How do you use numpy.mgrid with a variable number of indices? I can't find any examples on github of anyone using this with anything but hardcoded values.
import numpy as np
np.mgrid[1:10, 1:10] # this works fine
x = (1, 10)
np.mgrid[x[0]:x[1], x[0]:x[1]] # hardcoded
xs = [(1,10)] * 10
np.mgrid[*xs????] # I can't get anything to work here
This seems to work:
np.mgrid[[slice(i,j) for i,j in [(1,10)]*10]]
though with *10 it is too large
It's derived from that fact
np.mgrid[slice(1,10),slice(1,10)] # same as
np.mgrid[1:10,1:10]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With