当前位置:网站首页>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)
边栏推荐
- Data set partitioning and cross-validation
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- 再见了繁琐的Excel,掌握数据分析处理技术就靠它了
- Sword Point Offer Special Assault Edition ---- Day 2
- Input length must be multiple of 8 when decrypting with padded cipher
- C语言的文件操作(一)
- Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
- matlab simulink欠驱动水面船舶航迹自抗扰控制研究
- CentOS7 - yum install mysql
- Quickly master concurrent programming --- the basics
猜你喜欢
剑指offer基础版 --- 第21天
Unity mobile game performance optimization series: performance tuning for the CPU side
工作流编排引擎-Temporal
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
剑指offer基础版 ---- 第29天
Kubernetes 证书可用年限修改
mysql5.7.35安装配置教程【超级详细安装教程】
分布式事务处理方案大 PK!
数据库上机实验5 数据库安全性
实验8 DNS解析
随机推荐
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式
第7章 网络层第2次练习题答案(第三版)
限流的原理
第7章 网络层第3次练习题答案(第三版)
Data set partitioning and cross-validation
Element concatenation operations in numpy and pytorch: stack, concatenat, cat
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
实验7 UDP与TCP对比
mysql 的简单运用命令
[MQ I can speak for an hour]
CentOS7 - yum install mysql
Typec手机有线网卡网线转网口转接口快充方案
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
剑指offer基础版 ----- 第28天
数据库上机实验7 数据库设计
MySQL-Explain详解
剑指offer基础版 --- 第22天
torch.normal函数用法
第7章 网络层第1次练习题答案(第三版)