|
72 | 72 | "flipud",
|
73 | 73 | "hsplit",
|
74 | 74 | "hstack",
|
| 75 | + "matrix_transpose", |
75 | 76 | "moveaxis",
|
76 | 77 | "ndim",
|
77 | 78 | "permute_dims",
|
@@ -1751,6 +1752,53 @@ def hstack(tup, *, dtype=None, casting="same_kind"):
|
1751 | 1752 | return dpnp.concatenate(arrs, axis=1, dtype=dtype, casting=casting)
|
1752 | 1753 |
|
1753 | 1754 |
|
| 1755 | +def matrix_transpose(x, /): |
| 1756 | + """ |
| 1757 | + Transposes a matrix (or a stack of matrices) ``x``. |
| 1758 | +
|
| 1759 | + For full documentation refer to :obj:`numpy.matrix_transpose`. |
| 1760 | +
|
| 1761 | + Parameters |
| 1762 | + ---------- |
| 1763 | + x : (..., M, N) {dpnp.ndarray, usm_ndarray} |
| 1764 | + Input array with ``x.ndim >= 2` and whose two innermost |
| 1765 | + dimensions form ``MxN`` matrices. |
| 1766 | +
|
| 1767 | + Returns |
| 1768 | + ------- |
| 1769 | + out : dpnp.ndarray |
| 1770 | + An array containing the transpose for each matrix and having shape |
| 1771 | + (..., N, M). |
| 1772 | +
|
| 1773 | + See Also |
| 1774 | + -------- |
| 1775 | + :obj:`dpnp.transpose` : Returns an array with axes transposed. |
| 1776 | +
|
| 1777 | + Examples |
| 1778 | + -------- |
| 1779 | + >>> import dpnp as np |
| 1780 | + >>> a = np.array([[1, 2], [3, 4]]) |
| 1781 | + >>> np.matrix_transpose(a) |
| 1782 | + array([[1, 3], |
| 1783 | + [2, 4]]) |
| 1784 | +
|
| 1785 | + >>> b = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) |
| 1786 | + >>> np.matrix_transpose(b) |
| 1787 | + array([[[1, 3], |
| 1788 | + [2, 4]], |
| 1789 | + [[5, 7], |
| 1790 | + [6, 8]]]) |
| 1791 | +
|
| 1792 | + """ |
| 1793 | + |
| 1794 | + dpnp.check_supported_arrays_type(x) |
| 1795 | + if x.ndim < 2: |
| 1796 | + raise ValueError( |
| 1797 | + f"Input array must be at least 2-dimensional, but it is {x.ndim}" |
| 1798 | + ) |
| 1799 | + return dpnp.swapaxes(x, -1, -2) |
| 1800 | + |
| 1801 | + |
1754 | 1802 | def moveaxis(a, source, destination):
|
1755 | 1803 | """
|
1756 | 1804 | Move axes of an array to new positions. Other axes remain in their original
|
|
0 commit comments