在python中随机随机播放稀疏矩阵

在python中随机随机播放稀疏矩阵

问题描述:

有没有一种简单的方法可以在python中随机播放稀疏矩阵?

is there an easy way to shuffle a sparse matrix in python?

这是我改组非稀疏矩阵的方式:

This is how I shuffle a non-sparse matrix:

    index = np.arange(np.shape(matrix)[0])
    np.random.shuffle(index)
    return matrix[index]

我该如何用numpy稀疏处理呢?

How can I do it with numpy sparse?

好,找到了.稀疏格式在打印输出中看起来有些混乱.

Ok, found it. The sparse format looks a bit confusing in the print-out.

    index = np.arange(np.shape(matrix)[0])
    print index
    np.random.shuffle(index)
    return matrix[index, :]