import torch
tensor1 = torch.randn(3, 4)
print("tensor1 shape:", tensor1.shape)
print("tensor1内容:\n", tensor1)
tensor2 = torch.randn(2, 3, 5)
print("\ntensor2 shape:", tensor2.shape)
print("tensor2内容:\n", tensor2)
tensor3 = torch.randn(2, 2, dtype=torch.float64)
print("\ntensor3 dtype:", tensor3.dtype)
A = torch.tensor([[1], [2], [3]])
B = torch.tensor([[1, 2, 3, 4]])
C = A + B
print("A + B 的结果:\n", C)
X = torch.randn(2, 3, 4)
Y = torch.tensor([1, 2, 3, 4])
Z = X * Y
print("X * Y 的形状:", Z.shape)
import numpy as np
A = np.array([[1], [2], [3]])
B = np.array([[1, 2, 3, 4]])
C = A + B
print("Numpy A + B 的结果:\n", C)
import torch.nn as nn
x = torch.randn(1, 1, 5, 5)
conv_layer = nn.Conv2d(in_channels=1, out_channels=2, kernel_size=3)
output = conv_layer(x)
print("卷积输出形状:", output.shape)
pool_layer = nn.MaxPool2d(kernel_size=2, stride=2)
pooled = pool_layer(output)
print("池化输出形状:", pooled.shape)
@浙大疏锦行