简体   繁体   English

torch.addmm接收到无效的参数组合

[英]torch.addmm received an invalid combination of arguments

In the official webpage of pytorch I saw the following code with answers: 在pytorch的官方网页上,我看到了以下带有答案的代码:

>> a = torch.randn(4, 4)
>> a

0.0692  0.3142  1.2513 -0.5428
0.9288  0.8552 -0.2073  0.6409
1.0695 -0.0101 -2.4507 -1.2230
0.7426 -0.7666  0.4862 -0.6628
torch.FloatTensor of size 4x4]

>>> torch.max(a, 1)
(
 1.2513
 0.9288
 1.0695
 0.7426
[torch.FloatTensor of size 4]
,
 2
 0
 0
 0
[torch.LongTensor of size 4]
)

I know that the first result corresponds to the maximum number per row, however I do not get the second tensor (LongTensor) 我知道第一个结果对应于每行的最大数量,但是我没有得到第二个张量(LongTensor)

I tried other random example and after a pytorch.max, I came to find these results 我尝试了其他随机示例,并在pytorch.max之后,我找到了这些结果

0.9477  1.0090  0.8348 -1.3513
-0.4861  1.2581  0.3972  1.5751
-1.2277 -0.6201 -1.0553  0.6069
 0.1688  0.1373  0.6544 -0.7784
[torch.FloatTensor of size 4x4]

(
 1.0090
 1.5751
 0.6069
 0.6544
[torch.FloatTensor of size 4]
, 
 1
 3
 3
 2
[torch.LongTensor of size 4]
)

Can anyone tell me what does it really mean these LongTensor data? 谁能告诉我这些LongTensor数据的真正含义是什么? I thought it was a strange casting between tensors, however after a simple casting of a float tensor, I see that it just cuts decimals 我认为这是张量之间的奇怪转换,但是在简单地转换了浮点张量之后,我看到它只是将小数点减

Thanks 谢谢

It just tells the index of the max element in your original tensor along the queried dimension. 它只是告诉最大张量在原始张量中沿查询维度的索引

Eg 例如

0.9477  1.0090  0.8348 -1.3513
-0.4861  1.2581  0.3972  1.5751
-1.2277 -0.6201 -1.0553  0.6069
 0.1688  0.1373  0.6544 -0.7784
[torch.FloatTensor of size 4x4]

# torch.max(a, 1)
(
 1.0090
 1.5751
 0.6069
 0.6544
[torch.FloatTensor of size 4]
, 
 1
 3
 3
 2
[torch.LongTensor of size 4]
)

In the above example in torch.LongTensor , 在上例中的torch.LongTensor

1 is the index of 1.0090 in your original tensor (torch.FloatTensor) 1是原始张量(torch.FloatTensor)中的1.0090的索引
3 is the index of 1.5751 in your original tensor (torch.FloatTensor) 3是指数1.5751在你原来的张量(torch.FloatTensor)
3 is the index of 0.6069 in your original tensor (torch.FloatTensor) 3是原始张量(torch.FloatTensor)中的0.6069的索引
2 is the index of 0.6544 in your original tensor (torch.FloatTensor) 2是原始张量(torch.FloatTensor)中的0.6544指数

along dimension 1 . 沿尺寸1


Instead, if you'd have requested torch.max(a, 0) , the entries in torch.LongTensor would correspond to the indices of max elements in your original tensor along dimension 0 . 相反,如果您请求了torch.max(a, 0) ,则torch.LongTensor的条目将与原始张量中沿着维度0的max元素的indices相对应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 torch.Tensor() new() 收到了无效的 arguments 组合 - got (list, dtype=torch.dtype) - torch.Tensor() new() received an invalid combination of arguments - got (list, dtype=torch.dtype) RuntimeError:后端CUDA的预期对象,但后台CPU为参数:ret = torch.addmm(torch.jit._unwrap_optional(bias),input,weight.t()) - RuntimeError: Expected object of backend CUDA but got backend CPU for argument: ret = torch.addmm(torch.jit._unwrap_optional(bias), input, weight.t()) nn.LSTM() 收到 arguments 的无效组合 - nn.LSTM() received an invalid combination of arguments conv1d() 收到 arguments 的无效组合 - conv1d() received an invalid combination of arguments pytorch中参数的无效组合 - An invalid combination of arguments in pytorch Python:BERT Model 池错误 - mean() 收到了无效的 arguments 组合 - 得到(str,int) - Python: BERT Model Pooling Error - mean() received an invalid combination of arguments - got (str, int) 无效的参数组合 - eq() - Invalid combination of arguments - eq() 如何解决“TypeError: max() 收到无效的参数组合 - 得到(线性,int),但预期”? - How can I solve "TypeError: max() received an invalid combination of arguments - got (Linear, int), but expected"? 我如何摆脱这个错误:max() 收到了一个无效的参数组合 - 得到了 (str, int),但需要以下之一:*(张量输入) - How do I get rid of this error: max() received an invalid combination of arguments - got (str, int), but expected one of: * (Tensor input) RuntimeError:addmm():参数'mat1'(位置1)必须是Variable,而不是torch.FloatTensor - RuntimeError: addmm(): argument 'mat1' (position 1) must be Variable, not torch.FloatTensor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM