2012-08-27 50 views

回答

2

为了获得随机排序,您可以尝试使用np.random.shuffle函数。

# Create an array of indices 
indices = np.arange(y.size) 
# Randomize it 
np.random.shuffle(indices) 

您现在可以使用indices随机化y花哨的索引y_new = y[indices]

您可以使用相同的indices重新排列矩阵,但要小心,CSR矩阵不支持花哨的索引。您必须将其转换为LIL,对其重新排序,然后将其重新转换为CSR。