Returns an MXNet's NDArray backed by Numpy's ndarray.

    Parameters
    ----------
    ndarray: numpy.ndarray
        input data

    zero_copy: bool
        Whether we use DLPack's zero-copy conversion to convert to MXNet's NDArray.
        This is only available for c-contiguous arrays, i.e. array.flags[C_CONTIGUOUS] == True.

    Returns
    -------
    NDArray
        a NDArray backed by a dlpack tensor

def from_numpy(ndarray, zero_copy=True):
    """Returns an MXNet's NDArray backed by Numpy's ndarray.

    Parameters
    ----------
    ndarray: numpy.ndarray
        input data

    zero_copy: bool
        Whether we use DLPack's zero-copy conversion to convert to MXNet's NDArray.
        This is only available for c-contiguous arrays, i.e. array.flags[C_CONTIGUOUS] == True.

    Returns
    -------
    NDArray
        a NDArray backed by a dlpack tensor

    """

    def _make_manager_ctx(obj):
        pyobj = ctypes.py_object(obj)
        void_p = ctypes.c_void_p.from_buffer(pyobj)
        ctypes.pythonapi.Py_IncRef(pyobj)
        return void_p

    def _make_dl_tensor(array):
        if str(array.dtype) not in DLDataType.TYPE_MAP:
            raise ValueError(str(array.dtype) + " is not supported.")
        dl_tensor = DLTensor()
        dl_tensor.data = array.ctypes.data_as(ctypes.c_void_p)
        dl_tensor.ctx = DLContext(1, 0)
        dl_tensor.ndim = array.ndim
        dl_tensor.dtype = DLDataType.TYPE_MAP[str(array.dtype)]
        dl_tensor.shape = array.ctypes.shape_as(ctypes.c_int64)
        dl_tensor.strides = None
        dl_tensor.byte_offset = 0
        return dl_tensor

    def _make_dl_managed_tensor(array):
        c_obj = DLManagedTensor()
        c_obj.dl_tensor = _make_dl_tensor(array)
        c_obj.manager_ctx = _make_manager_ctx(array)
        c_obj.deleter = dl_managed_tensor_deleter
        return c_obj

    if not zero_copy:
        return array(ndarray, dtype=ndarray.dtype)

    if not ndarray.flags['C_CONTIGUOUS']:
        raise ValueError("Only c-contiguous arrays are supported for zero-copy")
    c_obj = _make_dl_managed_tensor(ndarray)
    address = ctypes.addressof(c_obj)
    address = ctypes.cast(address, ctypes.c_void_p)
    handle = NDArrayHandle()
    check_call(_LIB.MXNDArrayFromDLPack(address, ctypes.byref(handle)))
    return NDArray(handle=handle)