>= Operator sometimes casts vectors to matrices

Hi!

So the following pdb output states the question very clearly:

(Pdb) type(labels.cuda())
<class ‘torch.cuda.FloatTensor’>
(Pdb) type(predicted.data)
<class ‘torch.cuda.FloatTensor’>
(Pdb) predicted.data>=predicted.data

1
1
1
1
[torch.cuda.ByteTensor of size 4x1 (GPU 0)]

(Pdb) predicted.data>=labels.cuda()

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
[torch.cuda.ByteTensor of size 4x4 (GPU 0)]

So yeah, I am confused when it comes to the last output,is that intentional or a bug?

Hi,

I guess this is due to the broadcasting behaviour.
You can read about it here.
In your case, if predicted was a Tensor of size 4 instead of 4x1 I guess it would have the behavior you expect.

1 Like

Silly me, one was (4,1) the other (4,) :stuck_out_tongue: Thanks :slight_smile: