YouTip LogoYouTip

Pytorch Torch Inner

# Compute inner product result = torch.inner(a, b) print("Vector a:", a) print("Vector b:", b) print("Inner product result:", result)

The output result is:

Vector a: tensor([1., 2., 3.])Vector b: tensor([4., 5., 6.])Inner product result: tensor(32.)

Example - Matrix Inner Product

import torch

# Create two matrices

 A = torch.randn(2,3)

 B = torch.randn(2,3)

# Compute inner product on the last dimension

 result = torch.inner(A, B)

print("A Shape:", A.shape)

print("B Shape:", B.shape)

print("Result Shape:", result.shape)

Image 4: Pytorch torch Reference Manual Pytorch torch Reference Manual

← Pytorch Torch Is_AvailablePytorch Torch Inference_Mode β†’