I want to generate an n-dimensional grid.
For a 3D grid, I have the following working code (which creates a grid of 5X5X5 between (-1,1 )
import numpy as np
subdivision = 5
step = 1.0/subdivision
grid= np.mgrid[ step-1 : 1.0-step: complex(0, subdivision),
step-1 : 1.0-step: complex(0, subdivision),
step-1 : 1.0-step: complex(0, subdivision)]
I want to generalize this to n dimensions so something like
grid = np.mgrid[step-1 : 1.0-step: complex(0,subdivision) for i in range(n)]
But this obviously doesnt work. I also tried
temp = [np.linspace(step-1 , 1.0-step, subdivision) for i in range(D)]
grid = np.mgrid[temp]
But this doesn't work either since np.mgrid accepts slices
complex? With your 3D code I get 3x5x5x5. Is this intended?