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]])
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.meshgrid\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/numpy.py#L3599-L3633) |\n\nCreates grids of coordinates from coordinate vectors.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.keras.ops.numpy.meshgrid`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/meshgrid)\n\n\u003cbr /\u003e\n\n tf.keras.ops.meshgrid(\n *x, indexing='xy'\n )\n\nGiven `N` 1-D tensors `T0, T1, ..., TN-1` as inputs with corresponding\nlengths `S0, S1, ..., SN-1`, this creates an `N` N-dimensional tensors\n`G0, G1, ..., GN-1` each with shape `(S0, ..., SN-1)` where the output\n`Gi` is constructed by expanding `Ti` to the result shape.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|-----------------------------------------------------------------------------------------------|\n| `x` | 1-D tensors representing the coordinates of a grid. |\n| `indexing` | `\"xy\"` or `\"ij\"`. \"xy\" is cartesian; `\"ij\"` is matrix indexing of output. Defaults to `\"xy\"`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Sequence of N tensors. ||\n\n\u003cbr /\u003e\n\n#### Example:\n\n from keras.src import ops\n x = ops.array([1, 2, 3])\n y = ops.array([4, 5, 6])\n\n grid_x, grid_y = ops.meshgrid(x, y, indexing=\"ij\")\n grid_x\n array([[1, 1, 1],\n [2, 2, 2],\n [3, 3, 3]])\n grid_y\n array([[4, 5, 6],\n [4, 5, 6],\n [4, 5, 6]])"]]