meshgrid#
- ivy.meshgrid(*arrays, sparse=False, indexing='xy', out=None)[source]#
Return coordinate matrices from coordinate vectors.
- Parameters:
arrays (
Union
[Array
,NativeArray
]) – an arbitrary number of one-dimensional arrays representing grid coordinates. Each array should have the same numeric data type.sparse (
bool
, default:False
) – if True, a sparse grid is returned in order to conserve memory. Default:False
.indexing (
str
, default:'xy'
) – Cartesian'xy'
or matrix'ij'
indexing of output. If provided zero or one one-dimensional vector(s) (i.e., the zero- and one-dimensional cases, respectively), theindexing
keyword has no effect and should be ignored. Default:'xy'
.
- Return type:
List
[Array
]- Returns:
ret – list of N arrays, where
N
is the number of provided one-dimensional input arrays. Each returned array must have rankN
. ForN
one-dimensional arrays having lengthsNi = len(xi)
,if matrix indexing
ij
, then each returned array must have the shape(N1, N2, N3, ..., Nn)
.if Cartesian indexing
xy
, then each returned array must have shape(N2, N1, N3, ..., Nn)
.
Accordingly, for the two-dimensional case with input one-dimensional arrays of length
M
andN
, if matrix indexingij
, then each returned array must have shape(M, N)
, and, if Cartesian indexingxy
, then each returned array must have shape(N, M)
.Similarly, for the three-dimensional case with input one-dimensional arrays of length
M
,N
, andP
, if matrix indexingij
, then each returned array must have shape(M, N, P)
, and, if Cartesian indexingxy
, then each returned array must have shape(N, M, P)
.Each returned array should have the same data type as the input arrays.
This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.
Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2]) >>> y = ivy.array([3, 4]) >>> xv, yv = ivy.meshgrid(x, y) >>> print(xv) ivy.array([[1, 2], [1, 2]])
>>> print(yv) ivy.array([[3, 3], [4, 4]])
>>> x = ivy.array([1, 2, 5]) >>> y = ivy.array([4, 1]) >>> xv, yv = ivy.meshgrid(x, y, indexing='ij') >>> print(xv) ivy.array([[1, 1], [2, 2], [5, 5]])
>>> print(yv) ivy.array([[4, 1], [4, 1], [4, 1]])
>>> x = ivy.array([1, 2, 3]) >>> y = ivy.array([4, 5, 6]) >>> xv, yv = ivy.meshgrid(x, y, sparse=True) >>> print(xv) ivy.array([[1, 2, 3]])
>>> print(yv) ivy.array([[4], [5], [6]])
With
ivy.NativeArray
input:>>> x = ivy.native_array([1, 2]) >>> y = ivy.native_array([3, 4]) >>> xv, yv = ivy.meshgrid(x, y) >>> print(xv) ivy.array([[1, 2], [1, 2]])
>>> print(yv) ivy.array([[3, 3], [4, 4]])
- Array.meshgrid(self, /, *arrays, sparse=False, indexing='xy')[source]#
ivy.Array instance method variant of ivy.meshgrid. This method simply wraps the function, and so the docstring for ivy.meshgrid also applies to this method with minimal changes.
- Parameters:
self (
Array
) – one-dimensional input array.arrays (
Union
[Array
,NativeArray
]) – an arbitrary number of one-dimensional arrays representing grid coordinates. Each array should have the same numeric data type.sparse (
bool
, default:False
) – if True, a sparse grid is returned in order to conserve memory. Default:False
.indexing (
str
, default:'xy'
) – Cartesian'xy'
or matrix'ij'
indexing of output. If provided zero or one one-dimensional vector(s) (i.e., the zero- and one-dimensional cases, respectively), theindexing
keyword has no effect and should be ignored. Default:'xy'
.
- Return type:
List
[Array
]- Returns:
ret – list of N arrays, where
N
is the number of provided one-dimensional input arrays. Each returned array must have rankN
. ForN
one-dimensional arrays having lengthsNi = len(xi)
.