Python中文
首页
教程
问答
标签
搜索
登录
注册
Pytorch runtimeError“预期矩阵,在处获得1D、2D张量”
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我开始练习Pytorch,尝试使用torch.mm()方法</p> <p>下面是我的代码</p> <pre><code>import torch import numpy as np from torch.autograd import Variable num_x = np.array([[1.0, 2.0] ,[3.0,4.0]]) tensor_x = torch.from_numpy(num_x) x = Variable(tensor_x,requires_grad = True) s = Variable(torch.DoubleTensor([0.01,0.02]),requires_grad = True) print(s) s = s.mm(x) print(s) </code></pre> <p>不幸的是,有一个运行时错误</p> <pre><code>*RuntimeError Traceback (most recent call last) <ipython-input-58-e8a58ffb2545> in <module>() 9 s = Variable(torch.DoubleTensor([0.01,0.02]),requires_grad = True) 10 print(s) ---> 11 s = s.mm(x) 12 print(s) RuntimeError: matrices expected, got 1D, 2D tensors at /pytorch/aten/src/TH/generic/THTensorMath.cpp:131* </code></pre> <p>我怎样才能解决这个问题 谢谢你的答复</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>大约:</p> <pre><code>>>> s @ x tensor([0.0700, 0.1000], dtype=torch.float64, grad_fn=<SqueezeBackward3>) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何用if条件捕获函数返回值
10 回答
如何用if语句判断列表中是否存在该索引?
5 回答
如何用if语句向量化numpy数组中的最大值?
7 回答
如何用IF语句有条件地保存零碎的结果?
1 回答
如何用if语句测试异常对象?
1 回答
如何用IF语句编写二元函数
10 回答
如何用igraph在python中创建顶点权重的图?
2 回答
如何用ijson和python解析json
3 回答
如何用iloc求子矩阵
10 回答
如何用Imagemagick或PIL绘制高质量的图像笔划(边框)?
9 回答
如何用importlib在python中动态导入模块?
8 回答
如何用import语句重写python内置函数?
1 回答
如何用imshow混合裁剪的强度并显示正确的混合强度?
5 回答
如何用in dictionary解析havin dictionary中的json文件
3 回答
如何用in-Django URL替换%20
7 回答
如何用in\op正确构造查询
8 回答
如何用inbuild对象替换文件
7 回答
如何用inheritan类实现flask restful
8 回答
如何用intersphinx正确地编写对外部文档的交叉引用?
2 回答
如何用int修改LpVariable?
5 回答