pythonrandompytorchargumentstensor

What does it mean `torch.rand(1, 3, 64, 64)`?


I am beginner in PyTorch. In one tutorial, I saw: torch.rand(1, 3, 64, 64), I understand that it creates a Tensor with random numbers following standard normal distribution.

The outputs looks like:

tensor([[[[0.1352, 0.5110, 0.7585,  ..., 0.9067, 0.4730, 0.8077],
          [0.2471, 0.8726, 0.3580,  ..., 0.4983, 0.9747, 0.5219],
          [0.8554, 0.4266, 0.0718,  ..., 0.6734, 0.8739, 0.6137],
          ...,
          [0.2132, 0.9319, 0.5361,  ..., 0.3981, 0.2057, 0.7032],
          [0.3347, 0.5330, 0.7019,  ..., 0.6713, 0.0936, 0.4706],
          [0.6257, 0.6656, 0.3322,  ..., 0.6664, 0.8149, 0.1887]],

         [[0.3210, 0.6469, 0.7772,  ..., 0.3175, 0.5102, 0.9079],
          [0.3054, 0.2940, 0.6611,  ..., 0.0941, 0.3826, 0.3103],
          [0.7484, 0.3442, 0.1034,  ..., 0.8028, 0.4643, 0.2800],
          ...,
          [0.9946, 0.5868, 0.8709,  ..., 0.4837, 0.6691, 0.5303],
          [0.1770, 0.5355, 0.8048,  ..., 0.1843, 0.0658, 0.3817],
          [0.9612, 0.0122, 0.5012,  ..., 0.4198, 0.3294, 0.2106]],

         [[0.5800, 0.5174, 0.5454,  ..., 0.3881, 0.3277, 0.5470],
          [0.8871, 0.7536, 0.9928,  ..., 0.8455, 0.8071, 0.0062],
          [0.2199, 0.0449, 0.2999,  ..., 0.3570, 0.7996, 0.3253],
          ...,
          [0.8238, 0.1100, 0.1489,  ..., 0.0265, 0.2165, 0.2919],
          [0.4074, 0.5817, 0.8021,  ..., 0.3417, 0.1280, 0.9279],
          [0.0047, 0.1796, 0.4522,  ..., 0.3257, 0.2657, 0.4405]]]])

But what do the 4 arguments (1, 3, 64, 64) mean exactly? Thanks!


Solution

  • This is the shape of the output tensor. Specifically, it means that your output tensor has

    You can confirm this by comparing the number of elements with the tensor's "capacity":

    >>> torch.rand(1,3,64,64).numel()
    12288
    >>> 1 * 3 * 64 * 64
    12288