当前位置:网站首页>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)
边栏推荐
- Minio upload file ssl certificate is not trusted
- docker安装postgresSQL和设置自定义数据目录
- Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
- 第7章 网络层第3次练习题答案(第三版)
- Sword Point Offer Special Assault Edition ---- Day 2
- 数据库上机实验1 数据库定义语言
- 基于web3.0使用钱包Metamask的三方登陆
- 快速掌握并发编程 --- 基础篇
- 详解扫雷游戏(C语言)
- 面试官,不要再问我三次握手和四次挥手
猜你喜欢

About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)

C语言实验一 熟悉C程序的环境

The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays

面试官,不要再问我三次握手和四次挥手

目标检测学习笔记

第7章 网络层第2次练习题答案(第三版)

【MySQL8入门到精通】基础篇- Linux系统静默安装MySQL,跨版本升级

三子棋讲解(C语言)

数据库上机实验5 数据库安全性

剑指offer基础版 ----- 第25天
随机推荐
Interviewer, don't ask me to shake hands three times and wave four times again
Sword Point Offer Special Assault Edition ---- Day 1
剑指offer基础版 --- 第21天
PAT_乙级_真题练习_1007_素数对猜想
【C语言趣味小游戏——猜数字】
Quickly master concurrent programming --- the basics
Object Detection Study Notes
mysql 的简单运用命令
初涉C语言
剑指offer专项突击版 --- 第 3 天
Flask 的初识
Anaconda配置环境指令
The TOKEN value of Kubernetes joining the cluster expires
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
C语言指针详解
C语言教程(二)-printf及c自带的数据类型
如何将项目部署到服务器上(全套教程)
Temporal对比Cadence
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
三子棋讲解(C语言)