compas.utilities.meshgrid

compas.utilities.meshgrid(x, y, indexing='xy')[source]

Construct coordinate matrices from two coordinate vectors.

This function mimicks the functionality of numpy.meshgrid 1, but in a simpler form.

Parameters
  • x (list of float)

  • y (list of float)

  • indexing ({‘xy’, ‘ij’}, optional) – Default is 'xy'.

Returns

(list of list, list of list) – The X and Y values of the coordinate grid.

Examples

>>> from compas.utilities import linspace, meshgrid
>>> x = list(linspace(0, 1, 3))
>>> y = list(linspace(0, 1, 2))
>>> X, Y = meshgrid(x, y)
>>> X
[[0.0, 0.5, 1.0], [0.0, 0.5, 1.0]]
>>> Y
[[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]
>>> X, Y = meshgrid(x, y, 'ij')
>>> X
[[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]]
>>> Y
[[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]]

References

1

numpy.meshgrid Available at https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html