dimension out of range (expected to be in range of [-2, 1], but got 2)
Why does the following error popup? What should be in this range and why? What does -2 dimension mean?

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


This code will produce the error

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.


The following code snippet works.

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))

