python的新手,并试图学习文件i/o的绳索.
我正在使用以下格式从大型(200万行)文件中提取行:
56fr4
4543d
4343d
5irh3
Run Code Online (Sandbox Code Playgroud)
这是我用来返回代码的函数:
def getCode(i):
with open("test.txt") as f:
for index, line in enumerate(f):
if index == i:
code = # what does it equal?
break
return code
Run Code Online (Sandbox Code Playgroud)
一旦索引到达正确的位置(i),我使用什么语法来设置代码变量?
我想在填充序列上进行反向 LSTM,这需要在没有填充的情况下反转输入序列。
对于这样的批次(其中_代表填充):
a b c _ _ _
d e f g _ _
h i j k l m
Run Code Online (Sandbox Code Playgroud)
如果想得到:
c b a _ _ _
g f e d _ _
m l k j i h
Run Code Online (Sandbox Code Playgroud)
TensorFlow 有一个函数tf.reverse_sequence,它获取输入张量和批次中序列的长度并返回反向批次。在 Pytorch 中是否有一种简单的方法可以做到这一点?