Skip to content

asnumpy

Returns a dense numpy array from an arbitrary source array.

Parameters:

Name Type Description Default
a

Arbitrary object that can be converted to numpy.ndarray.

required
order

The desired memory layout of the output array. When order is 'A', it uses 'F' if a is fortran-contiguous and 'C' otherwise.

None

Returns:

Type Description
numpy.ndarray: Converted array on the host memory.
Source code in sparse/numba_backend/_common.py
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
def asnumpy(a, dtype=None, order=None):
    """Returns a dense numpy array from an arbitrary source array.

    Parameters
    ----------
    a: array_like
        Arbitrary object that can be converted to [`numpy.ndarray`][].
    order: ({'C', 'F', 'A'})
        The desired memory layout of the output
        array. When ``order`` is 'A', it uses 'F' if ``a`` is
        fortran-contiguous and 'C' otherwise.

    Returns
    -------
    numpy.ndarray: Converted array on the host memory.
    """
    from ._sparse_array import SparseArray

    if isinstance(a, SparseArray):
        a = a.todense()
    return np.asarray(a, dtype=dtype, order=order)