【发布时间】:2020-04-07 23:14:54
【问题描述】:
如何在 Pytorch 中将字符串列表转换为字符串/字符张量?
与 numpy 的相关示例:
import numpy as np
mylist = ["this","is","my","list"]
np.array([mylist])
返回:
array([['this', 'is', 'my', 'list']], dtype='<U4')
但是,在 pytorch 中:
torch.tensor(mylist)
返回:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-156-36722d81da09> in <module>
----> 1 torch.tensor(mylist)
ValueError: too many dimensions 'str'
张量是一个多维数组,所以我假设这可能是 pytorch。
注意:this post 没有回答我的问题
【问题讨论】:
-
According to the docs 没有字符串类型的张量。