We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7f8b6dc commit 9d82d12Copy full SHA for 9d82d12
beginner_source/blitz/tensor_tutorial.py
@@ -199,3 +199,18 @@
199
np.add(n, 1, out=n)
200
print(f"t: {t}")
201
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