Skip to content

Commit 18079ea

Browse files
authored
docs: Added docstring for COO.mT (#722)
1 parent 1163f77 commit 18079ea

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

docs/operations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ In these cases, they will produce an output with a fill value of `1` or `True`,
7777
assuming the original array has a fill value of `0` or `False` respectively.
7878

7979
If densification is needed, it must be explicit. In other words, you must call
80-
[`sparse.SparseArray.todense`][] on the [`sparse.SparseArray`][] object. If both operands are [sparse.SparseArray][],
80+
[`sparse.SparseArray.todense`][] on the [`sparse.SparseArray`][] object. If both operands are [`sparse.SparseArray`][],
8181
both must be densified.
8282

8383
**Operations with NumPy arrays**

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ plugins:
5959
show_if_no_docstring: true
6060
members_order: source
6161
docstring_style: numpy
62+
show_source: true
6263
filters: ["!^_"]
6364

6465
nav:

sparse/numba_backend/_coo/core.py

+34
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,40 @@ def T(self):
851851

852852
@property
853853
def mT(self):
854+
"""
855+
Transpose of a matrix (or a stack of matrices).
856+
If an array instance has fewer than two dimensions, an error should be raised.
857+
858+
Returns
859+
-------
860+
COO
861+
array whose last two dimensions (axes) are permuted in reverse order relative to
862+
original array (i.e., for an array instance having shape (..., M, N), the returned
863+
array must have shape (..., N, M)). The returned array must have the same data
864+
type as the original array.
865+
866+
See Also
867+
--------
868+
- [`sparse.COO.transpose`][] :
869+
A method where you can specify the order of the axes.
870+
- [`numpy.ndarray.mT`][] :
871+
Numpy equivalent property.
872+
873+
Examples
874+
--------
875+
>>> x = np.arange(8).reshape((2, 2, 2))
876+
>>> x # doctest: +NORMALIZE_WHITESPACE
877+
array([[[0, 1],
878+
[2, 3]],
879+
[[4, 5],
880+
[6, 7]]])
881+
>>> s = COO.from_numpy(x)
882+
>>> s.mT.todense() # doctest: +NORMALIZE_WHITESPACE
883+
array([[[0, 2],
884+
[1, 3]],
885+
[[4, 6],
886+
[5, 7]]])
887+
"""
854888
if self.ndim < 2:
855889
raise ValueError("Cannot compute matrix transpose if `ndim < 2`.")
856890

0 commit comments

Comments
 (0)