Difference between square bracket [] and curly () bracket in torch.randn()

There are two ways of creating random tensor :-
torch.randn([1,2], dtype=torch.float32, requires_grad=True)


torch.randn((1,2), dtype=torch.float32, requires_grad=True)

The random tensor’s dimension is 1x2 written in two ways [1,2] and (1,2).

Both of them returns a random tensor of 1x2 dimension. So, what is the difference between them?

There is no difference as you can specify the shape using a tuple, list, or direct arguments:

torch.randn(1, 2, dtype=torch.float32, requires_grad=True)

The list/tuple arguments are also supported in other classes e.g. in the kernel_size argument of conv layers:

nn.Conv2d(1, 1, kernel_size=(3, 3))
nn.Conv2d(1, 1, kernel_size=[3, 3])