Create 11

This commit is contained in:
xixu-me committed 2024-11-20 15:34:06 +08:00
1 parent 46c7ff872d
commit 0b47c6ece8
2 files changed
+55

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
import torch
print(f"PyTorch Version: {torch.__version__}")
matrix1 = torch.tensor(
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]], dtype=torch.float32
)
matrix2 = torch.tensor(
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], dtype=torch.float32
)
result = matrix1 @ matrix2
print("\nMatrix 1 (5 x 3):")
print(matrix1)
print("\nMatrix 2 (3 x 4):")
print(matrix2)
print("\nResult of matrix multiplication (5 x 4):")
print(result)
+35
View File
@@ -0,0 +1,35 @@
import torch
zeros = torch.zeros(3, 3)
ones = torch.ones(3, 3)
random_matrix = torch.rand(3, 3)
print("Zeros matrix:")
print(zeros)
print("\nOnes matrix:")
print(ones)
print("\nRandom matrix:")
print(random_matrix)
print("\nAbsolute value of random matrix:")
print(torch.abs(random_matrix))
print("\nAddition of ones and random matrix:")
print(ones + random_matrix)
print("\nDivision of random matrix by ones:")
print(random_matrix / ones)
print("\nDot product of random matrix with ones:")
print(random_matrix * ones)
print("\nCross product of random matrix with ones:")
print(random_matrix @ ones)
print("\nExponentiation of random matrix:")
print(torch.exp(random_matrix))
print("\nSize of matrices:")
print(f"Shape: {random_matrix.size()}")
print(f"Dimensions: {random_matrix.dim()}")
print(f"Total elements: {random_matrix.numel()}")