当前位置:网站首页>tf.keras.utils.pad_sequences()
tf.keras.utils.pad_sequences()
2022-07-31 05:34:00 【Erosion_ww】
Action:
Normalize length
This function converts a list (of length num_samples) of sequences (lists of integers) to a shape of (num_samples, num_timesteps) 2D Numpy array.num_timesteps is the maxlen parameter (if provided), or the longest sequence in the listlength.
shorter than num_timestepsThe sequences are filled with values until they are num_timesteps.
Longer than num_timestepsThe sequence will be truncated to fit the desired length.
The position where padding or truncation occurs is determined by parameter padding and truncation, respectively.Prefilling or removing values from the beginning of the sequence is the default.
parameter
tf.keras.utils.pad_sequences(sequences, # sequence lengthmaxlen=None, # optional Int, maximum length of all sequences.If not provided, the sequence will be padded to the length of the longest single sequence.dtype='int32', # optional, defaults to "int32".Type of output sequence.To pad a sequence with variable-length strings, you can use object.padding='pre', # string, "pre" or "post" (optional, defaults to "pre"): padding before or after each sequence.truncating='pre', # string, "pre" or "post" (optional, defaults to "pre"): Remove values from sequences greater than maxlen, whether at the beginning or end of the sequence.value=0.0 # float or string, fill value.(Optional, defaults to 0.))Return value
Numpy array with shape (len(sequences), maxlen)
Example
import tensorflow as tf # import tensorflowsequence = [[1], [2, 3], [4, 5, 6]] # input sequencetf.keras.preprocessing.sequence.pad_sequences(sequence) # length normalizationarray([[0, 0, 1],[0, 2, 3],[4, 5, 6]])
import tensorflow as tf # import tensorflowsequence = [[1], [2, 3], [4, 5, 6]] # input sequencetf.keras.preprocessing.sequence.pad_sequences(sequence, padding='post') # length normalizationarray([[1, 0, 0],[2, 3, 0],[4, 5, 6]])
Main reference: tf.keras.utils.pad_sequences | TensorFlow Core v2.9.1 (google.cn)
边栏推荐
- 梳理一下自己常用的快捷键
- 工作流编排引擎-Temporal
- Paginate the list collection and display the data on the page
- 1D, 2D, 3D convolution operations in pytorch
- tf.keras.utils.get_file()
- 【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
- 剑指offer基础版 --- 第24天
- 实验8 DNS解析
- pytorch中的一维、二维、三维卷积操作
- Anaconda configure environment directives
猜你喜欢
随机推荐
[mysql improves query efficiency] Mysql database query is slow to solve the problem
pycharm专业版使用
数据库学习笔记
面试官,不要再问我三次握手和四次挥手
C语言教程(二)-printf及c自带的数据类型
tf.keras.utils.get_file()
“档次法”——用于物品体积分布不均匀的01背包问题的求解方法
Pytorch教程Introduction中的神经网络实现示例
datagrip带参sql查询
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
【一起学Rust】Rust学习前准备——注释和格式化输出
mysql5.7.35安装配置教程【超级详细安装教程】
wx.miniProgram.navigateTo在web-view中跳回小程序并传参
Kubernetes加入集群的TOKEN值过期
MYSQL一站式学习,看完即学完
梳理一下自己常用的快捷键
C语言教程(一)-准备
MYSQL下载及安装完整教程
Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
Interviewer, don't ask me to shake hands three times and wave four times again









