MCPcopy Create free account
hub / github.com/numpy/numpy / cross

Function cross

numpy/core/numeric.py:1469–1667  ·  view source on GitHub ↗

Return the cross product of two (arrays of) vectors. The cross product of `a` and `b` in :math:`R^3` is a vector perpendicular to both `a` and `b`. If `a` and `b` are arrays of vectors, the vectors are defined by the last axis of `a` and `b` by default, and these axes can have

(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None)

Source from the content-addressed store, hash-verified

1467
1468@array_function_dispatch(_cross_dispatcher)
1469def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
1470 """
1471 Return the cross product of two (arrays of) vectors.
1472
1473 The cross product of `a` and `b` in :math:`R^3` is a vector perpendicular
1474 to both `a` and `b`. If `a` and `b` are arrays of vectors, the vectors
1475 are defined by the last axis of `a` and `b` by default, and these axes
1476 can have dimensions 2 or 3. Where the dimension of either `a` or `b` is
1477 2, the third component of the input vector is assumed to be zero and the
1478 cross product calculated accordingly. In cases where both input vectors
1479 have dimension 2, the z-component of the cross product is returned.
1480
1481 Parameters
1482 ----------
1483 a : array_like
1484 Components of the first vector(s).
1485 b : array_like
1486 Components of the second vector(s).
1487 axisa : int, optional
1488 Axis of `a` that defines the vector(s). By default, the last axis.
1489 axisb : int, optional
1490 Axis of `b` that defines the vector(s). By default, the last axis.
1491 axisc : int, optional
1492 Axis of `c` containing the cross product vector(s). Ignored if
1493 both input vectors have dimension 2, as the return is scalar.
1494 By default, the last axis.
1495 axis : int, optional
1496 If defined, the axis of `a`, `b` and `c` that defines the vector(s)
1497 and cross product(s). Overrides `axisa`, `axisb` and `axisc`.
1498
1499 Returns
1500 -------
1501 c : ndarray
1502 Vector cross product(s).
1503
1504 Raises
1505 ------
1506 ValueError
1507 When the dimension of the vector(s) in `a` and/or `b` does not
1508 equal 2 or 3.
1509
1510 See Also
1511 --------
1512 inner : Inner product
1513 outer : Outer product.
1514 ix_ : Construct index arrays.
1515
1516 Notes
1517 -----
1518 .. versionadded:: 1.9.0
1519
1520 Supports full broadcasting of the inputs.
1521
1522 Examples
1523 --------
1524 Vector cross-product.
1525
1526 >>> x = [1, 2, 3]

Callers

nothing calls this directly

Calls 9

normalize_axis_indexFunction · 0.85
moveaxisFunction · 0.85
promote_typesFunction · 0.85
negativeFunction · 0.85
astypeMethod · 0.80
asarrayFunction · 0.70
multiplyFunction · 0.70
arrayFunction · 0.70
emptyFunction · 0.50

Tested by

no test coverage detected