2012-08-27 53 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。