網站首頁 編程語言 正文
python常見的數據集打亂方法
第一種方法
通過index?
x_train, y_train=train_load()
index = [i for i in range(len(x_train))]
np.random.shuffle(index)
x_train= x_train[index]
y_train = y_train[index]
第二種方法
zip()+shuffle()方法
x_train, y_train=train_load()
result = list(zip(x_train, y_train)) ?# 打亂的索引序列
np.random.shuffle(result)
x_train,y_train = zip(*result)
第三種方法
seed()+shuffle
x_batch, y_batch = train_load()
#加載我所有的數據,這里想x_batch,Y_batch是list的格式,要注意
seed=100
random.seed(seed)
random.shuffle(x_batch)
random.seed(seed)#一定得重復在寫一遍,和上面的seed要相同,不然y_batch和x_batch打亂順序會不一樣
random.shuffle(y_batch)
PS:numpy中函數shuffle與permutation都是對原來的數組隨機打亂原來的順序,shuffle中文含義為洗牌,permutation中文含義為排列,區別在于shuffle直接在原來的數組上進行操作,改變原來數組的順序,無返回值。
而permutation不直接在原來的數組上進行操作,而是返回一個新的打亂順序的數組,并不改變原來的數組。
python手動打亂數據集
x_train, y_train = np.array(x_train),np.array(y_train)
index = [i for i in range(len(y_train))]
np.random.shuffle(index)
x_train = x_train[index]
y_train = y_train[index]
總結
原文鏈接:https://blog.csdn.net/weixin_40964777/article/details/100050263
相關推薦
- 2022-05-05 Python+OpenCV實現角度測量的示例代碼_python
- 2023-07-27 TypeScript類和多態、抽象類、訪問修飾符
- 2022-11-14 python中numpy?常用操作總結_python
- 2022-01-12 對比原生Node封裝的Express路由 和 express框架路由
- 2022-11-01 Android事件分發機制?ViewGroup分析_Android
- 2023-03-22 Go語言實現猜謎小游戲_Golang
- 2022-06-07 FreeRTOS實時操作系統移植操作示例指南_操作系統
- 2022-09-03 解決Python3錯誤:SyntaxError:?unexpected?EOF?while?pars
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支