# Create a grid of 3d positions

I want to create a function which return a 3d grid of 3d positions separated by intervals on each axis

*return type (list grid or array grid)

type t_grid = (float * float * float) list list list or type t_grid = (float * float * float) array array array

*here the signature :

create_grid width_x height_y depth_z inter_axis_x inter_axis_y inter_axis_z create_grid : int -> int -> int -> int -> int -> int -> t_grid

I don't really know how to handle this in an optimized way;

## Answers

It seems you are going to use this for numerical calculations. If your arrays have fixed size, better to use "array" than "list", because arrays are not resizeable. Lists have the overhead of nested linked structure. Beware that arrays cannot be larger than 2 million floats or so. Use "Bigarray" for larger arrays.

In fact, look into the documentation for the "Bigarray" module. It supports multidimensional arrays directly! This is surely much more efficient than a nested array of arrays. Look here:

http://caml.inria.fr/pub/docs/manual-ocaml/manual043.html http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html