如何使用带有可变数量索引的numpy.mgrid?我在github上找不到任何使用它的任何例子,除了硬编码值之外的任何东西。
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
答案 0 :(得分:4)
这似乎有效:
np.mgrid[[slice(i,j) for i,j in [(1,10)]*10]]
但是*10
太大了
它源自那个事实
np.mgrid[slice(1,10),slice(1,10)] # same as
np.mgrid[1:10,1:10]