Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何解决在使用torch.from_numpy时出现的Pytork UnicodeCodeer错误?_Python 3.x_Numpy_Pytorch - Fatal编程技术网

Python 3.x 如何解决在使用torch.from_numpy时出现的Pytork UnicodeCodeer错误?

Python 3.x 如何解决在使用torch.from_numpy时出现的Pytork UnicodeCodeer错误?,python-3.x,numpy,pytorch,Python 3.x,Numpy,Pytorch,我正在使用python3的PyTorch。 在ipdb模式下,我尝试了以下操作: regions = np.zeros([107,4], dtype='uint8') torch.from_numpy(regions) 这就是张量。 但是,在尝试时: regions = np.zeros([107,107,4], dtype='uint8') torch.from_numpy(regions) 我得到以下错误: *** UnicodeEncodeError: 'ascii' codec ca

我正在使用python3的PyTorch。 在ipdb模式下,我尝试了以下操作:

regions = np.zeros([107,4], dtype='uint8')
torch.from_numpy(regions)
这就是张量。 但是,在尝试时:

regions = np.zeros([107,107,4], dtype='uint8')
torch.from_numpy(regions)
我得到以下错误:

*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22ee' in position 72: ordinal not in range(128)
我正在使用:

numpy==1.11.3
torch==0.2.0.post4
torchvision==0.1.9

和python3.5.3

我可以在jupyter笔记本上运行两个版本的代码,而不会出现任何问题。我要说的是,这种Unicode编解码器错误不是由于
。from_numpy()

我正在运行Python 3.5.2 | Anaconda custom(x86_64)


从网站
http://pytorch.org/
他们说:

请确保您使用最新的pip和numpy软件包


我无法用最新版本的numpy和pytorch重现您的错误。我认为
pip install-U numpy
可能会解决这个问题。

为什么这个问题会被否决?我找到了几个解决方案,所有的答案都是一样的,试着找到您在脚本中导入的文件是什么,它使用open(filename)as,并将其更改为open(filename,encoding='utf8')as。这对我很管用。检查这些解决方案:,我有一个类似的问题,我尝试了你的建议,我仍然有同样的问题。
numpy==1.13.0
torch==0.1.12.post2
torchvision==0.1.8