meshgrid
- compas.utilities.meshgrid(x, y, indexing='xy')[source]
Construct coordinate matrices from two coordinate vectors.
- Parameters
x (list[float]) – The values of the “x axis” of the grid.
y (list[float]) – The values of the “y axis” of the grid.
indexing (Literal[‘xy’, ‘ij’], optional) – The indexing strategy determines the structure of the output.
- Returns
list[list[float]] – The X values of the coordinate grid.
list[list[float]] – The Y values of the coordinate grid.
Notes
The output of this function consists of two “matrices”, X and Y. The structure of the matrices is determined by the choice of indexing. Assuming
m = len(x)
andn = len(y)
. If indexing is'xy'
, the shape of both matrices is(n, m)
, with X containing the elements of x in its rows, and Y the elements of y in its columns. If indexing is'ij'
, the shape of both matrices is(m, n)
, with X containing the elements of x in its columns, and Y the elements of y in its rows.References
This function mimicks the functionality of
numpy.meshgrid
1, but in a simpler form.- 1
numpy.meshgrid. Available at https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html
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]]