From 9d82d12857167ed95c28385f22475e14b3d5069c Mon Sep 17 00:00:00 2001 From: Saisam32 <173052944+Sawsqr68@users.noreply.github.com> Date: Tue, 9 Dec 2025 13:09:08 +0300 Subject: [PATCH] Update tensor_tutorial.py --- beginner_source/blitz/tensor_tutorial.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/beginner_source/blitz/tensor_tutorial.py b/beginner_source/blitz/tensor_tutorial.py index ac54945bc3a..1c1e83ae949 100644 --- a/beginner_source/blitz/tensor_tutorial.py +++ b/beginner_source/blitz/tensor_tutorial.py @@ -199,3 +199,18 @@ np.add(n, 1, out=n) print(f"t: {t}") print(f"n: {n}") +data = [[1, 2], [3, 4]] +x_data = torch.tensor(data) +x_ones = torch.ones_like(x_data) # retains the properties of x_data +print(f"Ones Tensor: \n {x_ones} \n") + +x_rand = torch.rand_like(x_data, dtype=torch.float) # overrides the datatype of x_data +print(f"Random Tensor: \n {x_rand} \n") +shape = (2, 3,) +rand_tensor = torch.rand(shape) +ones_tensor = torch.ones(shape) +zeros_tensor = torch.zeros(shape) + +print(f"Random Tensor: \n {rand_tensor} \n") +print(f"Ones Tensor: \n {ones_tensor} \n") +print(f"Zeros Tensor: \n {zeros_tensor}")