栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

tf.data.Dataset.shuffle(buffer

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

tf.data.Dataset.shuffle(buffer

 

假定输入的数据为 A:=[0,1,2,3,4,5,6,7,8], buffer_sizer:=2.

A.shuffle(2)的工作思路:

 1.取A的 前两个元素 {0,1} 从中随机选出 1个元素, 例如 1. 原先的数据变为 A=[0,2,3,4,5,6,7,8]

 2. 重复1 至不能再重复

3. 将选出的元素按顺序写下.

上面的思路可以推论出 A 中第 i 个元素在 shuffle 后 只能出现在 第 i-1 个位置或更靠后.


 

dataset = tf.data.Dataset.from_tensor_slices([0, 1, 2,3,4, 5,6,7,8])
dataset1 = dataset.shuffle(2)
dataset = dataset.batch(3)


for elem in dataset1:
  print(elem)




#输出为
tf.Tensor(1, shape=(), dtype=int32)
tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor(4, shape=(), dtype=int32)
tf.Tensor(3, shape=(), dtype=int32)
tf.Tensor(5, shape=(), dtype=int32)
tf.Tensor(7, shape=(), dtype=int32)
tf.Tensor(6, shape=(), dtype=int32)
tf.Tensor(8, shape=(), dtype=int32)

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/657848.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号