--
PyTorch Tutorial
PyTorch TutorialPyTorch IntroductionPyTorch InstallationPyTorch BasicsPyTorch TensorsPyTorch Neural Network BasicsPyTorch First Neural NetworkPyTorch Data Processing and LoadingPyTorch Linear RegressionPyTorch Convolutional Neural NetworkPyTorch Recurrent Neural NetworkPyTorch DatasetsPyTorch Data TransformsPytorch torchPyTorch torch.nnTransformer ModelPyTorch TransformerPyTorch torch.optimPyTorch torchvisionPyTorch Model DeploymentPyTorch Model Saving and LoadingPyTorch Image ClassificationPyTorc Text Sentiment AnalysisPyTorch AutogradPyTorch GPU / CUDA AccelerationPyTorch Loss FunctionsPyTorch Learning Rate SchedulerPyTorch Transfer LearningPyTorch Batch NormalizationPyTorch LSTM / GRUPyTorch Word EmbeddingsPyTorch Generative Adversarial NetworksPyTorch AutoencodersPyTorch Model Evaluation and DebuggingPyTorch torchtextPyTorch Mixed Precision TrainingPyTorch TorchScript/ONNX ExportPyTorch Distributed TrainingPyTorch Attention Mechanism
PyTorch torch.nn Reference Manual
PyTorch torch.addmv Function
torch.addmv is a PyTorch function used to add the result of a matrix-vector multiplication to an input vector. It performs matrix-vector multiplication, then adds the result to input.
Function Definition
torch.addmv(input, mat, vec, *, beta=1.0, alpha=1.0, out=None) Parameters:
input(Tensor): Input vector or matrix to be added to the result.mat(Tensor): Input matrix with shape (n, m).vec(Tensor): Input vector with shape (m,) or (m, 1).beta(float, optional): Multiplier forinput, default is 1.0.alpha(float, optional): Multiplier for themat @ vecresult, default is 1.0.out(Tensor, optional): Output tensor.
Returns:
torch.Tensor: Returns the sum of the matrix-vector multiplication result and the input vector.
Usage Example
Example
import torch
Create input vector, matrix, and vector
input= torch.randn(3)
mat = torch.randn(3,4)
vec = torch.randn(4)
Execute addmv
result = torch.addmv(input, mat, vec)
print("Input vector shape:",input.shape)
print("Matrix shape:", mat.shape)
print("Vector shape:", vec.shape)
print("Result shape:", result.shape)
print(result)
Output:
Input vector shape: torch.Size()Matrix shape: torch.Size([3, 4])Vector shape: torch.Size()Result shape: torch.Size() tensor([-1.0182, -0.4901, -0.9490])
YouTip