you can use
np.mgrid[[slice(row[0], row[1], n*1j) for row, n in zip(bounds, n_bins)]]
import numpy as np D = 3 n_bins = 100*np.ones(D) bounds = np.repeat([(0,1)], D, axis = 0) result = np.mgrid[[slice(row[0], row[1], n*1j) for row, n in zip(bounds, n_bins)]] ans = np.mgrid[0:1:100j,0:1:100j,0:1:100j] assert np.allclose(result, ans)
Note that np.ogrid can be used in many places where np.mgrid used and requires less memory because arrays are smaller.
source share