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
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
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)