sisl / GridInterpolations.jl

Multidimensional grid interpolation in arbitrary dimensions
Other
52 stars 12 forks source link

Generate rectangle of dimension N #28

Closed eloualiche closed 4 years ago

eloualiche commented 4 years ago

This might be already doable but I cannot figure it out. I am trying to generate a N-dimensional rectangular grid where N is a parameter.

So if my grid is

grid_1d = [0., 0.5, 1.]
N = 2
grid = RectangleGrid(grid_1d, grid_1d)

Of course this is a little annoying for more dimensions

N=6
grid = RectangleGrid(grid_1d, grid_1d, grid_1d, grid_1d, grid_1d, grid_1d)

I looked into the constructor but was not able to figure out an elegant way of programmatically implement my rectangle.

Any help would be appreciated!


Thank you for the great and useful package.

MaximeBouton commented 4 years ago

There are no built in way of doing this. You could use a list comprehension and splatting as a more elegant way.

N = 6
grid = RectangleGrid([grid_1d for i=1:N]...)

This is if grid_1d is the same for all your dimensions.

eloualiche commented 4 years ago

Thanks! Sorry for such basic question but I could not figure out a proper syntax.

MaximeBouton commented 4 years ago

no problem!