Got scalar value of 7.0 directly by using example_tensor[1,1,0]

I didn’t get a tensor when I did example_tensor[1,1,0]. Why?
Because of this, I need not use .item().
Python 3.9.7
Torch 1.10.0
This is in optional lab on PyTorch.
Even for mean and standard deviation, I am not getting tensor outputs. Directly getting scalar outputs only.

@Kartik_Podugu, do you mean that when you execute the cell in the Indexing Tensors section with the code example_tensor[1,1,0], you’re not getting back a tensor? It seems to be returning a tensor for me:

Yes @Wendy , I am directly getting scalar value only. not sure why

Interesting. I suppose it could be due to the versions you’re using, although I’m surprised they would change this intentionally, since it could break existing code that was using .item().

If I launch in the browser to use Coursera’s Jupyter notebook, I am using
Python 3.7.6
Torch 1.4.0

If you use the browser notebook, you should see the same behavior I’m seeing and that the developer expected for this assignment.

If you’re curious, you can try these same versions on your local environment and see if that gives you consistent behavior. Feel free to experiment after that to see if you can isolate which version change caused the difference you’re seeing, and if newer torch versions go back to the behavior seen in the browser (w/ torch v1.4.0)

In general, launching in the browser will give you the most-tested configuration, and you’re less likely to run into version-specific issues than if you run locally.