I try to create a meshgrid with n dimensions. Is there a nicer way to call meshgrid with n column vectors than with the if clause I am using?
Edit: The goal is to use it for user-defined n (2-100) without writing 100 if clauses.
The second line in the if clauses reduces the grid so column(n) < column(n+1)
Example:
import numpy as np
dimension = 2
range = np.arange(0.2,2.4,0.1)
if dimension == 2:
grid = np.array(np.meshgrid(range,range)).T.reshape(-1,dimension)
grid = np.array(grid[[i for i in range(grid.shape[0]) if grid[i,0]<grid[i,1]]])
elif dimension == 3:
grid = np.array(np.meshgrid(range,range,range)).T.reshape(-1,dimension)
grid = np.array(grid[[i for i in range(grid.shape[0]) if grid[i,0]<grid[i,1]]])
grid = np.array(grid[[i for i in range(grid.shape[0]) if grid[i,1]<grid[i,2]]])
Edit: The solution was posted below:
dimension = 2
r = np.arange(0.2,2.4,0.1)
grid=np.array(np.meshgrid(*[r]*n)).T.reshape(-1,n)
for i in range(0,n-1):
grid = np.array([g for g in grid if g[i]<g[i+1]])