当前位置:网站首页>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)
边栏推荐
- 剑指offer基础版 ---- 第26天
- 如何将项目部署到服务器上(全套教程)
- Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
- Kubernetes 证书可用年限修改
- Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
- 剑指offer专项突击版 ---- 第1天
- Lock wait timeout exceeded解决方案
- Unity mobile game performance optimization series: performance tuning for the CPU side
- wpf ScrowViewer水平滚动
- 快速掌握并发编程 --- 基础篇
猜你喜欢

再见了繁琐的Excel,掌握数据分析处理技术就靠它了

剑指offer专项突击版 ---- 第1天

剑指offer专项突击版 --- 第 4 天

剑指offer基础版 ----- 第25天

Distributed transaction processing solution big PK!

C语言实验三 选择结构程序设计

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

Lock wait timeout exceeded解决方案

matlab simulink欠驱动水面船舶航迹自抗扰控制研究

MySQL-Explain详解
随机推荐
Typec手机有线网卡网线转网口转接口快充方案
Pytorch教程Introduction中的神经网络实现示例
数据库上机实验5 数据库安全性
Temporal介绍
限流的原理
tf.keras.utils.get_file()
梳理一下自己常用的快捷键
Anaconda配置环境指令
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
wpf wrapPanel居中并从左到右排列
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
详解扫雷游戏(C语言)
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
Swordsman Offer Special Assault Edition ---- Day 6
If the account number or password is entered incorrectly for many times, the account will be banned.
MySQL_关于JSON数据的查询
工作流编排引擎-Temporal
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
实验8 DNS解析
Mysql——字符串函数