Don't understand a runtime error with torch.randn

Hi everyone,

So I’m working on my assignement for the first week and I was trying to use the dtype argument with torch.randn. And I can’t figure out if I do something wrong or if I’m missing something as usually errors are Syntax one.

So i tried to type:

I also tried to type the dtype argument as follow with the same results :

  • dtype=torch.int
  • dtype=torch.intTensor

While those arguments work well :

  • dtype=torch.float
  • dtype=torch.double

So I was wondering if the error is normal (i.e. torch.randn is intended to produce only float numbers) or if I type something wrong and torch.randn is actually capable of producing a tensor filled with integers.

Thanks

The random numbers generated will follow a normal distribution which will be centered at zero. They will be float or double but cannot be integers.

If you wanna generate random integers you can use torch.randint() instead
https://pytorch.org/docs/master/generated/torch.randint.html

Cheers
Aris

1 Like

Thanks a lot, I was pretty sure this function was meant to generate only float but wasn’t sure.