Skip to content

Commit 9d82d12

Browse files
authored
Update tensor_tutorial.py
1 parent 7f8b6dc commit 9d82d12

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

beginner_source/blitz/tensor_tutorial.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,18 @@
199199
np.add(n, 1, out=n)
200200
print(f"t: {t}")
201201
print(f"n: {n}")
202+
data = [[1, 2], [3, 4]]
203+
x_data = torch.tensor(data)
204+
x_ones = torch.ones_like(x_data) # retains the properties of x_data
205+
print(f"Ones Tensor: \n {x_ones} \n")
206+
207+
x_rand = torch.rand_like(x_data, dtype=torch.float) # overrides the datatype of x_data
208+
print(f"Random Tensor: \n {x_rand} \n")
209+
shape = (2, 3,)
210+
rand_tensor = torch.rand(shape)
211+
ones_tensor = torch.ones(shape)
212+
zeros_tensor = torch.zeros(shape)
213+
214+
print(f"Random Tensor: \n {rand_tensor} \n")
215+
print(f"Ones Tensor: \n {ones_tensor} \n")
216+
print(f"Zeros Tensor: \n {zeros_tensor}")

0 commit comments

Comments
 (0)