Np.asarray behaviour in pytorch and tensorflow

Hello. I want my as output same as tensorflow output, but i’m unable to figuring out how array behaves? Why np.array perform the same way as in tensorflow and what is the difference between the output of tensorflow and pytorch, desdpite that both are tensors with dim = 10? Is there any other thing which i’m doing wrong

tensorflow output = [1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]
pytorch output = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]

Hi @muhibkhan,

There are both the same, of shape (10). The difference you see is just an aesthetic difference in the printing.
If you print tensor1 or tensor2 shape and type in PyTorch you will have:

torch.Size([10]), torch.float32

which is strictly equivalent to TensorFlow’s TensorShape([Dimension(10)]) that you see.

So logically both outputs like:
tensorflow output = [1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]
pytorch output = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]

are same. Comma separation (,) doesn’t have any affect.

Correct, that’s what I meant. :slightly_smiling_face:

1 Like