Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Added docstring for COO.mT #722

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ In these cases, they will produce an output with a fill value of `1` or `True`,
assuming the original array has a fill value of `0` or `False` respectively.

If densification is needed, it must be explicit. In other words, you must call
[`sparse.SparseArray.todense`][] on the [`sparse.SparseArray`][] object. If both operands are [sparse.SparseArray][],
[`sparse.SparseArray.todense`][] on the [`sparse.SparseArray`][] object. If both operands are [`sparse.SparseArray`][],
hameerabbasi marked this conversation as resolved.
Show resolved Hide resolved
both must be densified.

**Operations with NumPy arrays**
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ plugins:
show_if_no_docstring: true
members_order: source
docstring_style: numpy
show_source: true
filters: ["!^_"]

nav:
Expand Down
34 changes: 34 additions & 0 deletions sparse/numba_backend/_coo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,40 @@ def T(self):

@property
def mT(self):
"""
Transpose of a matrix (or a stack of matrices).
If an array instance has fewer than two dimensions, an error should be raised.

Returns
-------
COO
array whose last two dimensions (axes) are permuted in reverse order relative to
original array (i.e., for an array instance having shape (..., M, N), the returned
array must have shape (..., N, M)). The returned array must have the same data
type as the original array.

See Also
--------
- [`sparse.COO.transpose`][] :
A method where you can specify the order of the axes.
- [`numpy.ndarray.mT`][] :
Numpy equivalent property.

Examples
--------
>>> x = np.arange(8).reshape((2, 2, 2))
>>> x # doctest: +NORMALIZE_WHITESPACE
array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> s = COO.from_numpy(x)
>>> s.mT.todense() # doctest: +NORMALIZE_WHITESPACE
array([[[0, 2],
[1, 3]],
[[4, 6],
[5, 7]]])
"""
if self.ndim < 2:
raise ValueError("Cannot compute matrix transpose if `ndim < 2`.")

Expand Down
Loading