def csr_data_indices(arr):
    """extract data and indices arrays from a dense vector

    (this may seem like it may be done faster with np.array.nonzero
    and similar tools, but this implementation is faster)

    :param arr: dense array
    :return: arrays with nonzero data elements, and corresponding indices
    """

    data, indices = [], []
    for i in range(len(arr)):
        if arr[i] != 0.0:
            data.append(arr[i])
            indices.append(i)
    return data, indices