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 must hav
(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None)
| 1561 | |
| 1562 | @array_function_dispatch(_cross_dispatcher) |
| 1563 | def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None): |
| 1564 | """ |
| 1565 | Return the cross product of two (arrays of) vectors. |
| 1566 | |
| 1567 | The cross product of `a` and `b` in :math:`R^3` is a vector perpendicular |
| 1568 | to both `a` and `b`. If `a` and `b` are arrays of vectors, the vectors |
| 1569 | are defined by the last axis of `a` and `b` by default, and these axes |
| 1570 | must have 3 dimensions. |
| 1571 | |
| 1572 | Parameters |
| 1573 | ---------- |
| 1574 | a : array_like |
| 1575 | Components of the first vector(s). |
| 1576 | b : array_like |
| 1577 | Components of the second vector(s). |
| 1578 | axisa : int, optional |
| 1579 | Axis of `a` that defines the vector(s). By default, the last axis. |
| 1580 | axisb : int, optional |
| 1581 | Axis of `b` that defines the vector(s). By default, the last axis. |
| 1582 | axisc : int, optional |
| 1583 | Axis of `c` containing the cross product vector(s). By default, the last axis. |
| 1584 | axis : int, optional |
| 1585 | If defined, the axis of `a`, `b` and `c` that defines the vector(s) |
| 1586 | and cross product(s). Overrides `axisa`, `axisb` and `axisc`. |
| 1587 | |
| 1588 | Returns |
| 1589 | ------- |
| 1590 | c : ndarray |
| 1591 | Vector cross product(s). |
| 1592 | |
| 1593 | Raises |
| 1594 | ------ |
| 1595 | ValueError |
| 1596 | When the dimension of the vector(s) in `a` or `b` does not equal 3. |
| 1597 | |
| 1598 | See Also |
| 1599 | -------- |
| 1600 | inner : Inner product |
| 1601 | outer : Outer product. |
| 1602 | linalg.cross : An Array API compatible variation of ``np.cross``. |
| 1603 | ix_ : Construct index arrays. |
| 1604 | |
| 1605 | Notes |
| 1606 | ----- |
| 1607 | Supports full broadcasting of the inputs. |
| 1608 | |
| 1609 | Examples |
| 1610 | -------- |
| 1611 | Vector cross-product. |
| 1612 | |
| 1613 | >>> import numpy as np |
| 1614 | >>> x = [1, 2, 3] |
| 1615 | >>> y = [4, 5, 6] |
| 1616 | >>> np.cross(x, y) |
| 1617 | array([-3, 6, -3]) |
| 1618 | |
| 1619 | One vector with dimension 2. |
| 1620 |