chenyuntc / pytorch-book

PyTorch tutorials and fun projects including neural talk, neural style, poem writing, anime generation (《深度学习框架PyTorch:入门与实战》)
MIT License
12.06k stars 3.74k forks source link

二重列表生成式 #99

Closed TJJTJJTJJ closed 5 years ago

TJJTJJTJJ commented 6 years ago

在第九章的main.py的可视化操作中

poetrys = [[ix2word[_word] for _word in data_[:, _iii].tolist()] for _iii in range(data_.shape[1])][:16]

在运行一次的时候是可以的,但是

18it [00:01, 14.47it/s]> /home/zbp/Linux/tjj/pytorchtest/chapter9-神经网络写诗(CharRNN)/main.py(177)train()
    176                 ipdb.set_trace()
--> 177                 poetrys = [[ix2word[_word] for _word in data_[:, _iii].tolist()] for _iii in range(data_.shape[1])][:16]
    178                 vis.text('</br>'.join([''.join(poetry) for poetry in poetrys]), win=u'origin_poem')

ipdb> n
> /home/zbp/Linux/tjj/pytorchtest/chapter9-神经网络写诗(CharRNN)/main.py(178)train()
    177                 poetrys = [[ix2word[_word] for _word in data_[:, _iii].tolist()] for _iii in range(data_.shape[1])][:16]
--> 178                 vis.text('</br>'.join([''.join(poetry) for poetry in poetrys]), win=u'origin_poem')
    179 

18it [00:20,ipdb> poetr = [[ix2word[_word] for _word in data_[:, _iii].tolist()] for _iii in range(data_.shape[1])][:16]
*** NameError: name 'data_' is not defined

我试图在ipdb中重新运行这一句代码,就会出现提示data没有定义的情况,现在基本可以确定,是指data[:, _iii].tolist()的data_没有定义,这个就很诡异了。 想问一下大家,这个是因为什么,在命令行界面反而不能行。在文件里却可以。 希望得到大家的解答

chenyuntc commented 5 years ago

这个,和列表生成式没有关系,单纯就是data_这个变量没有定义。建议检查一下命令行界面的输入,是否漏掉了什么