Shuffle arrays or sparse matrices in a consistent way
This is a convenience alias to resample(*arrays, replace=False)
to do random permutations of the collections.
Parameters: |
*arrays : sequence of indexable data-structures
random_state : int or RandomState instance
n_samples : int, None by default
|
---|---|
Returns: |
shuffled_arrays : sequence of indexable data-structures
|
# -*- coding: utf-8 -*-
"""
Spyder Editor This is a temporary script file.
""" import numpy as np X = np.array([[1., 0.], [2., 1.], [0., 0.]])
y = np.array([0, 1, 2]) from scipy.sparse import coo_matrix
X_sparse = coo_matrix(X) print '稀疏矩阵%s\n',X_sparse from sklearn.utils import shuffle
X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)
print 'X值\n', X print 'X_sparse值\n', X_sparse print 'y值\n', y '''
稀疏矩阵%s
(0, 0) 1.0
(1, 0) 2.0
(1, 1) 1.0
X值
[[ 0. 0.]
[ 2. 1.]
[ 1. 0.]]
X_sparse值
(1, 1) 1.0
(1, 0) 2.0
(2, 0) 1.0
y值
[2 1 0]
'''