megengine.functional.cross¶
- cross(a, b, axisa=- 1, axisb=- 1, axisc=- 1, axis=None)[source]¶
Return the cross product of two (arrays of) vectors.
The cross product of
a
andb
in R^3 is a vector perpendicular to botha
andb
. Ifa
andb
are arrays of vectors, the vectors are defined by the last axis ofa
andb
by default, and these axes can have dimensions 2 or 3. Where the dimension of eithera
orb
is 2, the third component of the input vector is assumed to be zero and the cross product calculated accordingly.- Parameters
a (
Tensor
) – components of the first vector(s).b (
Tensor
) – components of the first vector(s).axisa (
int
) – axis of a that defines the vector(s). By default, the last axis.axisb (
int
) – axis of b that defines the vector(s). By default, the last axis.axisc (
int
) – axis of c containing the cross product vector(s). By default, the last axis.axis (
Optional
[int
]) – if defined, the axis of a, b and c that defines the vector(s) and cross product(s). Overrides axisa, axisb and axisc.
- Return type
- Returns
vector cross product(s).
Examples
>>> a = Tensor([1.0, 2.0, 3.0]) >>> b = Tensor([4.0, 5.0, 6.0]) >>> out = F.cross(a, b) >>> out.numpy() array([-3., 6., -3.], dtype=float32)