I really like the feature that I can read a 2D matrix row-by-row using a for-loop.
a = torch.FloatTensor(4, 4).random_()
for b in a:
print(b)
However, if the size of the 2D matrix is 0, this would throw an error.
a = torch.FloatTensor(0, 4).random_()
for b in a:
print(b)
It gives an error saying that RuntimeError: dimension 0 out of range of 0D tensor at /py/conda-bld/pytorch_1493677666423/work/torch/lib/TH/generic/THTensor.c:24
I tried with numpy and it works fine with matrix of size 0.
a = np.random.uniform(size=(0, 4))
for b in a:
print(b)
I am not sure if it is a bug. If this can be “fixed”, it would be helpful as we don’t need to check the size of the matrix before the for-loop.