简体   繁体   English

随机播放 numpy 数组而不拆分

[英]Shuffle numpy array without split

I have a 4D numpy array for input to a CNN similar to this generated data:我有一个 4D numpy数组用于输入CNN类似于此生成的数据:

import numpy as np
X = np.random.rand(20, 1, 10, 4)

And the corresponding label (in a separate array) y is而相应的 label(在一个单独的数组中) y

y = [0,0,0,....0]

So that the first instance of my input looks like:这样我输入的第一个实例看起来像:

>>>X[0]
array([[[0.11529038, 0.56951377, 0.64859216, 0.53927201],
        [0.24599472, 0.99658675, 0.61760602, 0.23245005],
        [0.21688713, 0.87376011, 0.80853348, 0.95649564],
        [0.01096112, 0.36735236, 0.23917356, 0.06020551],
        [0.14795334, 0.31689876, 0.902638  , 0.95702681],
        [0.59684508, 0.53496984, 0.91312413, 0.17465782],
        [0.37409845, 0.51140496, 0.32453245, 0.59066936],
        [0.64259922, 0.6586773 , 0.13101008, 0.71666185],
        [0.59971516, 0.96920186, 0.8566649 , 0.37763693],
        [0.34957495, 0.88521399, 0.30383687, 0.23567811]]])

>>>len(y)
20

I would like to shuffle my data set before feeding into the.network but I cannot use sklearn train_test_split which split the data into the train-test.我想在输入 .network 之前洗牌我的数据集,但我不能使用 sklearn train_test_split将数据拆分为训练测试。 My dataset is already separated into train test but would like to shuffle before the model fit.我的数据集已经分离到训练测试中,但想在 model 适合之前洗牌。

train_idx = np.random.permutation(train_set.shape[0])
train_x, train_y = train_x[train_idx], train_y[train_idx]

Similarly for val and test.对于 val 和 test 也是如此。

sklearn has a shuffle method sklearn 有一个shuffle方法

from sklearn.utils import shuffle
X, y = shuffle(X, y)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM