Pytorch counting tensor
I am trying to create a Python function that, given inputs dim and m, generates the tensor of size [m ** dim, dim] of the form
[[1,...,1,1],
 [1,...,1,2],
 ...
 [1,...,1,m],
 [1,...,2,1],
 [1,...,2,2],
 ...
 [m,...,m,m]]

What is the best way of doing this in Pytorch?
Thanks

I have solved this myself using the following code:
import torch
import numpy as np

def mat_gen(dim, m): 
    return torch.from_numpy(np.array(np.meshgrid(*[np.arange(1, m + 1, 1) for i in range(dim)])).T.reshape(m ** dim, dim))

Here is another function that uses Pytorch only:
import torch

def mat_gen(dim, m): 
    return torch.stack(torch.meshgrid(*[torch.arange(1, m + 1, 1) for i in range(dim)])).T.reshape(m ** dim, dim)

