当前位置:网站首页>tf.keras.utils.pad_sequences()
tf.keras.utils.pad_sequences()
2022-07-31 05:09:00 【Erosion_ww】
作用:
使长度标准化
此函数将序列(lists of integers)的列表(of length num_samples)转换为形状为(num_samples,num_timesteps)的 2D Numpy 数组。 num_timesteps是 maxlen 参数(如果提供),或者是列表中最长序列的长度。
短于 num_timesteps 的序列用值填充,直到它们长 num_timesteps。
长于 num_timesteps 的序列将被截断,以使其符合所需的长度。
发生填充或截断的位置分别由参数填充和截断决定。 从序列的开头预填充或删除值是默认设置。
参数
tf.keras.utils.pad_sequences(
sequences, # 序列长度
maxlen=None, # 可选 Int,所有序列的最大长度。 如果未提供,序列将被填充到最长的单个序列的长度。
dtype='int32', # 可选,默认为“int32”。 输出序列的类型。 要使用可变长度字符串填充序列,可以使用 object.
padding='pre', # 字符串,“pre”或“post”(可选,默认为“pre”):在每个序列之前或之后填充。
truncating='pre', # 字符串,“pre”或“post”(可选,默认为“pre”):从大于 maxlen 的序列中删除值,无论是在序列的开头还是结尾。
value=0.0 # 浮点数或字符串,填充值。 (可选,默认为 0。)
)返回值
Numpy array with shape (len(sequences), maxlen)
例子
import tensorflow as tf # 导入tensorflow
sequence = [[1], [2, 3], [4, 5, 6]] # 输入序列
tf.keras.preprocessing.sequence.pad_sequences(sequence) # 长度标准化
array([[0, 0, 1],
[0, 2, 3],
[4, 5, 6]])import tensorflow as tf # 导入tensorflow
sequence = [[1], [2, 3], [4, 5, 6]] # 输入序列
tf.keras.preprocessing.sequence.pad_sequences(sequence, padding='post') # 长度标准化array([[1, 0, 0],
[2, 3, 0],
[4, 5, 6]])主要参考:tf.keras.utils.pad_sequences | TensorFlow Core v2.9.1 (google.cn)
边栏推荐
- Summary of MySQL common interview questions (recommended collection!!!)
- CentOS7 - yum install mysql
- Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
- MySQL-Explain详解
- matlab abel变换图片处理
- centos7安装mysql5.7步骤(图解版)
- DVWA之SQL注入
- Unity框架设计系列:Unity 如何设计网络框架
- 城市内涝及桥洞隧道积水在线监测系统
- 工作流编排引擎-Temporal
猜你喜欢
【一起学Rust】Rust学习前准备——注释和格式化输出

ES 源码 API调用链路源码分析
![2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。](/img/7f/130a9b733855a2bab07d26ffda2c49.png)
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。

matlab abel变换图片处理

Go language study notes - dealing with timeout problems - Context usage | Go language from scratch

Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it

MySQL-Explain详解

MySQL (updating)

信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作

pycharm专业版使用
随机推荐
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
为什么要用Flink,怎么入门使用Flink?
[Detailed explanation of ORACLE Explain]
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
Temporal对比Cadence
STM32 - DMA
Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
MYSQL下载及安装完整教程
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
datagrip带参sql查询
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
Reference code series_1. Hello World in various languages
With MVC, why DDD?
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
Linux系统安装mysql(rpm方式安装)
mysql5.7.35安装配置教程【超级详细安装教程】
PWN ROP
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)