Skip to content

Commit d516108

Browse files
Viacheslav Kovalevskyiholly1238
Viacheslav Kovalevskyi
andauthored
Misc updates in tensor_tutorial (#1696)
* making spaces after comma more consistent in tensor_tutorial * after moving tensor to GPU, tutorial code is now showing that tensor is on the GPU in tensor_tutorial Co-authored-by: Holly Sweeney <77758406+holly1238@users.noreply.github.com>
1 parent 521b123 commit d516108

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

beginner_source/blitz/tensor_tutorial.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#
2828
# Tensors can be created directly from data. The data type is automatically inferred.
2929

30-
data = [[1, 2],[3, 4]]
30+
data = [[1, 2], [3, 4]]
3131
x_data = torch.tensor(data)
3232

3333
######################################################################
@@ -55,7 +55,7 @@
5555
#
5656
# ``shape`` is a tuple of tensor dimensions. In the functions below, it determines the dimensionality of the output tensor.
5757

58-
shape = (2,3,)
58+
shape = (2, 3,)
5959
rand_tensor = torch.rand(shape)
6060
ones_tensor = torch.ones(shape)
6161
zeros_tensor = torch.zeros(shape)
@@ -78,7 +78,7 @@
7878
#
7979
# Tensor attributes describe their shape, datatype, and the device on which they are stored.
8080

81-
tensor = torch.rand(3,4)
81+
tensor = torch.rand(3, 4)
8282

8383
print(f"Shape of tensor: {tensor.shape}")
8484
print(f"Datatype of tensor: {tensor.dtype}")
@@ -107,6 +107,7 @@
107107
# We move our tensor to the GPU if available
108108
if torch.cuda.is_available():
109109
tensor = tensor.to('cuda')
110+
print(f"Device tensor is stored on: {tensor.device}")
110111

111112

112113
######################################################################

0 commit comments

Comments
 (0)