gpt4 book ai didi

pytorch - 维度超出范围(预期在 [-2, 1] 范围内,但得到 2)

转载 作者:行者123 更新时间:2023-12-01 13:19:43 25 4
gpt4 key购买 nike

为什么会弹出以​​下错误?这个范围内应该是什么,为什么? -2 维是什么意思?

RuntimeError: dimension out of range (expected to be in range of [-2, 1], but got 2)

此代码将产生错误
import torch 

torch.bmm(torch.randn(1000, 784) , torch.randn(784, 10))

最佳答案

torch.mm :

Performs a matrix multiplication of the matrices mat1 and mat2.

If mat1 is a (n×m) tensor, mat2 is a (m×p) tensor, out will be a (n×p) tensor.



torch.bmm :

Performs a batch matrix-matrix product of matrices stored in batch1 and batch2.

batch1 and batch2 must be 3-D tensors each containing the same number of matrices.

If batch1 is a (b×n×m) tensor, batch2 is a (b×m×p) tensor, out will be a (b×n×p) tensor.



以下代码片段有效。
import torch

x = torch.mm(torch.randn(100, 78) , torch.randn(78, 10))
bsize = 16
x = torch.bmm(torch.randn(bsize, 100, 78) , torch.randn(bsize, 78, 10))

关于pytorch - 维度超出范围(预期在 [-2, 1] 范围内,但得到 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50776744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com