""" numpy.random.shuffle(x) Modify a sequence in-place by shuffling its contents. random.shuffle(list)只能对list进行随机打乱。 Parameters: x : array_like The array or list to be shuffled. Returns: None This function only shuffles the array along the first index of a multi-dimensional array (多维矩阵中,只对第一维(行)做打乱顺序操作) """ import numpy as np arr = np.arange(10) arr
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
1 2
np.random.shuffle(arr) arr
array([1, 4, 7, 3, 0, 9, 5, 8, 2, 6])
1 2
arr = np.arange(9).reshape((3, 3)) arr
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
1 2 3
# 对于矩阵,按照row进行打乱。 np.random.shuffle(arr) arr
array([[3, 4, 5],
[0, 1, 2],
[6, 7, 8]])
1 2 3
# 对于矩阵,按照row进行打乱。 np.random.shuffle(arr) arr
array([[3, 4, 5],
[6, 7, 8],
[0, 1, 2]])
1 2
# random.shuffle(list) l = [i for i in xrange(0,10)]
import time import random import numpy as np train_data = (np.array([[1,1], [2,2], [3,3], [4,4]]), np.array([11,22,33,44])) x = train_data[0] y = train_data[1]
originX = shared_x.get_value(borrow=True) originY = shared_y.get_value(borrow=True) print originX is x # true print originY is y # true shuffle_data(originX,originY)
print train_data
print'\nshared x and y' print shared_x.get_value() print shared_y.get_value()
WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10). Please switch to the gpuarray backend. You can get more information about how to switch at this URL:
https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: Unable to get the number of gpus available: no CUDA-capable device is detected)
TensorType(float64, matrix) TensorType(int32, vector) TensorType(int32, vector)
<class 'theano.tensor.sharedvar.TensorSharedVariable'> <class 'theano.tensor.sharedvar.TensorSharedVariable'> <class 'theano.tensor.sharedvar.TensorSharedVariable'>
True
old train
(array([[ 1., 1.],
[ 2., 2.],
[ 3., 3.],
[ 4., 4.]]), array([11, 22, 33, 44], dtype=int32))
shuffle train
True
True
(array([[ 4., 4.],
[ 3., 3.],
[ 1., 1.],
[ 2., 2.]]), array([44, 33, 11, 22], dtype=int32))
shared x and y
[[ 4. 4.]
[ 3. 3.]
[ 1. 1.]
[ 2. 2.]]
[44 33 11 22]