首页 > 其他分享 >keras.preprocessing.sequence.pad_sequences()的用法

keras.preprocessing.sequence.pad_sequences()的用法

时间:2023-05-08 10:12:27浏览次数:35  
标签:pre keras sequence preprocessing pad sequences 序列

1.pad_sequences()的作用

keras只能接受长度相等的序列输入。当我们的数据集中出现了长度不等的序列时,可以使用pad_sequence()函数将序列转化为经过填充以后得到的一个长度相同新的序列。

2.pad_sequences()语法

 

1 keras.preprocessing.sequence.pad_sequences(
2     sequences,
3     maxlen=None,
4     dtype='int32',
5     padding='pre',
6     truncting='pre',
7     value=0)

 

3.pad_sequences()的输入参数

  • sequences:浮点数或整数构成的两层嵌套列表
  • maxlen:None或整数,为序列的最大长度。大于此长度的将被截断,小于此长度的序列将在后面填0.
  • dtype:返回的numpy array的数据类型。
  • paddingprepost,确定当需要补0时,在序列的起始还是结尾补。
  • truncatingprepost,确定需要截断序列时,从起始还是结尾截断。
  • value:浮点数,用于填充序列。

 

标签:pre,keras,sequence,preprocessing,pad,sequences,序列
From: https://www.cnblogs.com/FrankJin/p/17380859.html

相关文章

  • 1163 Dijkstra Sequence + 层序遍历 + 链式前向星
    PAT题目链接:https://pintia.cn/problem-sets/994805342720868352/exam/problems/1478635670373253120这题踩了太多坑,本来没什么内容,硬是断断续续查了三天的bug:第一天:循环的时候内部判断逻辑不要写在for循环里,否则本该continue的逻辑,硬生生变成了break。我真是脑袋瓜秀逗了才会......
  • CF750E - New Year and Old Subsequence
    题意:给一个字符串,每次询问它的一个区间,问最少删除多少个字符,使得区间没有子序列2016,但是有子序列2017。Mysolution首先考虑贪心,通过预处理的方式找到区间最后一个7,依次往前贪心的找到最靠后的一组2017。接下来,我们需要7的后面没有6,7前面的部分不能组合出2016。我们先......
  • PAT Advanced 1007. Maximum Subsequence Sum
    PATAdvanced1007.MaximumSubsequenceSum1.ProblemDescription:Givenasequenceof\(K\)integers{\(N_1,N_2,...,N_K\)}.Acontinuoussubsequenceisdefinedtobe{\(N_i,N_{i+1},...,N_j\)}where\(1≤i≤j≤K\).TheMaximumSubsequencei......
  • rgi main --input_sequence temp/out_pro.fa --output_file result/protein --inpu
    这是一个命令行命令,用于对temp/out_pro.fa文件进行抗菌基因分析。参数的含义如下:rgi:表示运行resistantgeneidentifier(rgi)程序。main:指定使用rgi的主要模式。--input_sequencetemp/out_pro.fa:指定输入序列文件名和路径。--output_fileresult/protein:指......
  • AtCoder Regular Contest 134 D Concatenate Subsequences
    洛谷传送门AtCoder传送门我一年前甚至不会做/qd发现\(a_{x_1}\)为\(k=\min\limits_{i=1}^na_i\)时最优。然后开始分类讨论:如果\(\min\limits_{a_i=k}a_{i+n}\lek\),答案为\((k,\min\limits_{a_i=k}a_{i+n})\)。这是因为如果再选一个\(k\)肯定不优。否则......
  • [ABC299F] Square Subsequence
    ProblemStatementYouaregivenastring$S$consistingoflowercaseEnglishletters.Printthenumberofnon-emptystrings$T$thatsatisfythefollowingcondition,modulo$998244353$.Theconcatenation$TT$oftwocopiesof$T$isasubsequenceof$S$(......
  • Tablespace 'innodb_system' Page [page id: space=0, page number=5] log sequence n
    场景:这几天在外面实习,老师的项目数据库崩了让我看,连着两条看到十一二点,哎。主要场景是mysql突然崩溃,发现重启mysqld服务无效,重启系统无效。查看/var/log/mysql.log日志,看到以下内容:Themanualpageathttp://dev.mysql.com/doc/mysql/en/crashing.htmlcontainsinfo......
  • CF1814E Chain Chips & CF750E New Year and Old Subsequence - 动态 dp -
    一句话概括动态dp:用来解决带修改/多次区间询问的dp问题。将转移写成矩阵的形式,然后利用线段树求解区间问题/单点修改1814E注意一条边要么选2要么选0次,而且第一条边一定是选了2次。如果有一条边没选,那么这条边两侧的边一定都选了。设\(f_i\)代表考虑到第\(i\)条边,......
  • 使用GPU加速TensorFlow-Keras
    之前一直在用CPU训练TensorFlow模型,现在来尝试一下GPU训练。【1】安装GPU必要的软件环境显卡:MX450(支持CUDA11.7以下版本)软件1:VisualStudio2019Community软件2:Cuda10.1update2软件3:cuDNN8.0.5forwin10(x86) 环境:在Anacodna中专门建立tensorflow_gpu环境Python3.7......
  • Codeforces Round #450 (Div. 2) D. Unusual Sequences 数学
    Countthenumberofdistinctsequencesa1, a2, …, an(1 ≤ ai)consistingofpositiveintegerssuchthatgcd(a1, a2, …, an) = xand.Asthisnumbercouldbelarge,printtheanswermodulo109 + 7.gcdheremeansthegreatestcommondivisor.Input......