Code Explanation:
Import PyTorch:
import torch
PyTorch is a library used for tensor computations, deep learning, and machine learning.
2. Define Tensors x and y:
x = torch.tensor([1.0, 2.0])
y = torch.tensor([3.0, 4.0])
x is a 1-dimensional tensor (vector) with elements [1.0, 2.0].
y is another 1-dimensional tensor with elements [3.0, 4.0].
3. Compute the Dot Product:
result = torch.dot(x, y)
The torch.dot() function computes the dot product of two 1D tensors (vectors).
Formula for the dot product:
dot(๐ฅ,๐ฆ)=๐ฅ1⋅๐ฆ1+๐ฅ2⋅๐ฆ2
4. Print the Result:
print(result)
Outputs the result of the dot product computation.
Final Output:
tensor(11.)
torch.dot() returns a scalar tensor with the result of the dot product.
tensor(11.) indicates a PyTorch tensor containing the value 11.0.
0 Comments:
Post a Comment