fn

meshgrid

list of Tensor
meshgrid(tensors: Tensor = (), indexing: str = 'ij')
source

Construct coordinate grids from 1-D coordinate vectors.

Given k 1-D inputs of sizes n_1, ..., n_k, returns k tensors of shape (n_1, ..., n_k) ('ij' indexing) or (n_2, n_1, n_3, ..., n_k) ('xy' indexing) such that out[i][...] enumerates the i-th coordinate.

Parameters

*tensorsTensor= ()
1-D coordinate tensors.
indexingstr= ``'ij'``
'ij' for matrix-style indexing, 'xy' for Cartesian indexing (swaps the first two output axes).

Returns

list of Tensor

len(tensors) coordinate grids.

Notes

The 'xy' convention matches NumPy's default and is convenient for plotting; 'ij' matches the broadcasting/reduction conventions used elsewhere in tensor libraries.

Examples

>>> import lucid
>>> x = lucid.tensor([1, 2, 3])
>>> y = lucid.tensor([4, 5])
>>> gx, gy = lucid.meshgrid(x, y, indexing='ij')
>>> gx.shape, gy.shape
((3, 2), (3, 2))