跳到内容

asnumpy

从任意源数组返回一个稠密的 numpy 数组。

参数

名称 类型 描述 默认值
a

可以转换为 numpy.ndarray 的任意对象。

必需
order

输出数组所需的内存布局。当 order 为 'A' 时,如果 a 是 Fortran 连续的,则使用 'F',否则使用 'C'。

None

返回值

类型 描述
numpy.ndarray: 宿主内存上的转换数组。
源代码位于 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)