import torch

tensor = torch.arange(7).reshape(7, 1)

permuted_tensor = tensor.permute(1, 0)
permuted_tensor=permuted_tensor.float()

randt = torch.rand(7, 1, dtype=torch.float)
prod = permuted_tensor @ randt

print("\nMatrix multiplication result:")
print(prod)

import torch

device = torch.device("cuda")

tensor = torch.randn(2, 2)
tensor = tensor.to(device)

print(tensor)
print(tensor.device)

import torch

tensor = torch.arange(7).reshape(7, 1)

permuted_tensor = tensor.permute(1, 0)
permuted_tensor=permuted_tensor.float()

randt = torch.rand(7, 1, dtype=torch.float)
prod = permuted_tensor @ randt

prodt=tensor.permute(1,0)
prodt=prodt.float()

prodf= prod @ prodt

print(prodf)

Edit

Pub: 04 Jan 2025 06:07 UTC

Views: 22