当前位置:网站首页>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)
边栏推荐
- Unity mobile game performance optimization series: performance tuning for the CPU side
- Create componentized development based on ILRuntime hot update
- [debug highlights] Expected input batch_size (1) to match target batch_size (0)
- [R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
- 一文了解大厂的DDD领域驱动设计
- TOGAF之架构标准规范(一)
- Multiple table query of sql statement
- STM32 - DMA
- ES source code API call link source code analysis
- ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)
猜你喜欢

On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels

Centos7 install mysql5.7 steps (graphical version)

DVWA安装教程(懂你的不懂·详细)

MySQL忘记密码怎么办
【一起学Rust】Rust学习前准备——注释和格式化输出

DVWA靶场环境搭建

Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
![[debug highlights] Expected input batch_size (1) to match target batch_size (0)](/img/b3/ff6ccc3cd307befad3bd07a9f4a956.png)
[debug highlights] Expected input batch_size (1) to match target batch_size (0)

EasyExcel的简单读取操作

mysql uses on duplicate key update to update data in batches
随机推荐
CentOS7 —— yum安装mysql
MySQL forgot password
关于LocalDateTime的全局返回时间带“T“的时间格式处理
EasyExcel的简单读取操作
The monitoring of Doris study notes
MySQL transaction isolation level, rounding
1. 获取数据-requests.get()
可点击也可直接复制指定内容js
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
MySQL优化之慢日志查询
Summary of MySQL common interview questions (recommended collection!!!)
[C language] Detailed explanation of operators
ABC D - Distinct Trio(k元组的个数
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
MySQL optimization slow log query
面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式
Create componentized development based on ILRuntime hot update
DVWA安装教程(懂你的不懂·详细)
SQL row-column conversion
Doris学习笔记之监控