Broadcasts parameters for evaluation on an N-D grid. Given N one-dimensional coordinate arrays `*args`, returns a list `outputs` of N-D coordinate arrays for evaluating expressions on an N-D grid. Notes: `meshgrid` supports cartesian ('xy') and matrix ('ij') indexing conventions. When t
(*args, **kwargs)
| 2872 | |
| 2873 | @tf_export("meshgrid") |
| 2874 | def meshgrid(*args, **kwargs): |
| 2875 | """Broadcasts parameters for evaluation on an N-D grid. |
| 2876 | |
| 2877 | Given N one-dimensional coordinate arrays `*args`, returns a list `outputs` |
| 2878 | of N-D coordinate arrays for evaluating expressions on an N-D grid. |
| 2879 | |
| 2880 | Notes: |
| 2881 | |
| 2882 | `meshgrid` supports cartesian ('xy') and matrix ('ij') indexing conventions. |
| 2883 | When the `indexing` argument is set to 'xy' (the default), the broadcasting |
| 2884 | instructions for the first two dimensions are swapped. |
| 2885 | |
| 2886 | Examples: |
| 2887 | |
| 2888 | Calling `X, Y = meshgrid(x, y)` with the tensors |
| 2889 | |
| 2890 | ```python |
| 2891 | x = [1, 2, 3] |
| 2892 | y = [4, 5, 6] |
| 2893 | X, Y = tf.meshgrid(x, y) |
| 2894 | # X = [[1, 2, 3], |
| 2895 | # [1, 2, 3], |
| 2896 | # [1, 2, 3]] |
| 2897 | # Y = [[4, 4, 4], |
| 2898 | # [5, 5, 5], |
| 2899 | # [6, 6, 6]] |
| 2900 | ``` |
| 2901 | |
| 2902 | Args: |
| 2903 | *args: `Tensor`s with rank 1. |
| 2904 | **kwargs: |
| 2905 | - indexing: Either 'xy' or 'ij' (optional, default: 'xy'). |
| 2906 | - name: A name for the operation (optional). |
| 2907 | |
| 2908 | Returns: |
| 2909 | outputs: A list of N `Tensor`s with rank N. |
| 2910 | |
| 2911 | Raises: |
| 2912 | TypeError: When no keyword arguments (kwargs) are passed. |
| 2913 | ValueError: When indexing keyword argument is not one of `xy` or `ij`. |
| 2914 | """ |
| 2915 | |
| 2916 | indexing = kwargs.pop("indexing", "xy") |
| 2917 | name = kwargs.pop("name", "meshgrid") |
| 2918 | if kwargs: |
| 2919 | key = list(kwargs.keys())[0] |
| 2920 | raise TypeError("'{}' is an invalid keyword argument " |
| 2921 | "for this function".format(key)) |
| 2922 | |
| 2923 | if indexing not in ("xy", "ij"): |
| 2924 | raise ValueError("indexing parameter must be either 'xy' or 'ij'") |
| 2925 | |
| 2926 | with ops.name_scope(name, "meshgrid", args) as name: |
| 2927 | ndim = len(args) |
| 2928 | s0 = (1,) * ndim |
| 2929 | |
| 2930 | # Prepare reshape by inserting dimensions with size 1 where needed |
| 2931 | output = [] |
no test coverage detected