当前位置:网站首页>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 normalization
array([[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 normalization
array([[1, 0, 0],[2, 3, 0],[4, 5, 6]])
Main reference: tf.keras.utils.pad_sequences | TensorFlow Core v2.9.1 (google.cn)
边栏推荐
猜你喜欢
随机推荐
第7章 网络层第3次练习题答案(第三版)
matlab simulink欠驱动水面船舶航迹自抗扰控制研究
Kubernetes 证书可用年限修改
mysql5.7.35安装配置教程【超级详细安装教程】
Why use Flink and how to get started with Flink?
Paginate the list collection and display the data on the page
The TOKEN value of Kubernetes joining the cluster expires
Apache DButils使用注意事项--with modifiers “public“
Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
Shell重油常压塔模拟仿真与控制
数据库上机实验4 数据更新和视图
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
面试官问我TCP三次握手和四次挥手,我真的是
“档次法”——用于物品体积分布不均匀的01背包问题的求解方法
C语言指针详解
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
uni-app进阶之生命周期【day8】
剑指offer基础版 ----第31天
Distributed transaction processing solution big PK!
关于LocalDateTime的全局返回时间带“T“的时间格式处理