当前位置:网站首页>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)
边栏推荐
- MySQL-如何分库分表?一看就懂
- DVWA安装教程(懂你的不懂·详细)
- [Cloud Native] DevOps (5): Integrating Harbor
- MySQL optimization slow log query
- Reference code series_1. Hello World in various languages
- CentOS7 install MySQL graphic detailed tutorial
- Sql解析转换之JSqlParse完整介绍
- Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
- Shell重油常压塔模拟仿真与控制
- Create componentized development based on ILRuntime hot update
猜你喜欢
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
mysql使用on duplicate key update批量更新数据
PWN ROP
MySQL_关于JSON数据的查询
ERP Production Operation Control Kingdee
Linux系统安装mysql(rpm方式安装)
DVWA之SQL注入
pycharm专业版使用
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
Create componentized development based on ILRuntime hot update
随机推荐
Simple read operation of EasyExcel
SQL语句中对时间字段进行区间查询
pycharm专业版使用
限流的原理
centos7安装mysql5.7步骤(图解版)
关于LocalDateTime的全局返回时间带“T“的时间格式处理
.NET-6.WinForm2.NanUI学习和总结
精解四大集合框架:List 核心知识总结
EasyExcel的简单读取操作
[mysql improves query efficiency] Mysql database query is slow to solve the problem
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
【一起学Rust】Rust的Hello Rust详细解析
MySQL (updating)
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
With MVC, why DDD?
Centos7 install mysql5.7
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
Paginate the list collection and display the data on the page
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)