Skip to content

permute_dims

Permutes the axes (dimensions) of an array x.

Parameters:

Name Type Description Default
x

input array.

required
axes

tuple containing a permutation of (0, 1, ..., N-1) where N is the number of axes (dimensions) of x.

None

Returns:

Name Type Description
out array

an array containing the axes permutation. The returned array must have the same data type as x.

Examples:

>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
>>> o = sparse.permute_dims(a, axes=(1, 0))
>>> o.todense()
array([[0, 2],
       [1, 0]])
Source code in sparse/numba_backend/_common.py
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
def permute_dims(x, /, axes=None):
    """
    Permutes the axes (dimensions) of an array ``x``.

    Parameters
    ----------
    x: array
        input array.
    axes: Tuple[int, ...]
        tuple containing a permutation of ``(0, 1, ..., N-1)`` where ``N`` is the number of axes (dimensions)
        of ``x``.

    Returns
    -------
    out: array
        an array containing the axes permutation. The returned array must have the same data type as ``x``.

    Examples
    --------
    >>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
    >>> o = sparse.permute_dims(a, axes=(1, 0))
    >>> o.todense()  # doctest: +NORMALIZE_WHITESPACE
    array([[0, 2],
           [1, 0]])
    """

    return x.transpose(axes=axes)