tf.keras.ops.meshgrid
Stay organized with collections Save and categorize content based on your preferences.
Creates grids of coordinates from coordinate vectors.
tf.keras.ops.meshgrid( *x, indexing='xy' )
Given N
1-D tensors T0, T1, ..., TN-1
as inputs with corresponding lengths S0, S1, ..., SN-1
, this creates an N
N-dimensional tensors G0, G1, ..., GN-1
each with shape (S0, ..., SN-1)
where the output Gi
is constructed by expanding Ti
to the result shape.
Args |
x | 1-D tensors representing the coordinates of a grid. |
indexing | "xy" or "ij" . "xy" is cartesian; "ij" is matrix indexing of output. Defaults to "xy" . |
Returns |
Sequence of N tensors. |
Example:
from keras.src import ops
x = ops.array([1, 2, 3])
y = ops.array([4, 5, 6])
grid_x, grid_y = ops.meshgrid(x, y, indexing="ij")
grid_x
array([[1, 1, 1],
[2, 2, 2],
[3, 3, 3]])
grid_y
array([[4, 5, 6],
[4, 5, 6],
[4, 5, 6]])