<jupyter_start><jupyter_text>快速入门学习<jupyter_code>import torch.nn as nn
import torch.nn.functional as F
import torch
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(1, 6, 5)
        self.conv2 = nn.Conv2d(6, 16, 5)
        self.fc1 = nn.Linear(400, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)
    
    def forward(self, x):
        x = F.max_pool2d(F.relu(self.conv1(x)),(2, 2))
        x = F.max_pool2d(F.relu(self.conv2(x)), 2)
        x = x.view(x.size()[0], -1)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x
net = Net()
net
params = list(net.parameters())
len(params)
for name,parameters in net.named_parameters():
    print(name,':',parameters.size())
input = torch.rand(1, 1, 32, 32)
input
out = net.forward(input)
out<jupyter_output><empty_output><jupyter_text>tensor学习<jupyter_code># arrange 与 linspace 的区别如下
a = torch.arange(1, 5, 0.5)
b = torch.linspace(1, 5, 6)
print("a:", a)
print("b:", b)
# 创建tensor 以list
a = [[1,2,3],[3,4,5]]
a = torch.Tensor(a)
print(a.tolist())    # list 与 tensor相互转换
# 以成员元素具体值来创建Tensor
# () [] 创建结果相同
c = torch.Tensor(((1, 3), (2, 3)))
d = torch.Tensor([[1, 3],[2, 3]])

print(c.equal(d))
# 区别：分布不同，randn是标准正态，rand是均匀分布
e = torch.randn(5)
f = torch.rand(5)
print(e)
print(f)
# tensor 与 Tensor
# tensor 的操作基本类似于 numpy
scalar = torch.tensor(1)
h = torch.Tensor(1)
print(scalar.shape)
print(h.shape)

vector = torch.tensor([1, 3])     # 不可以torch.tensor(1, 3) 
tensor = torch.Tensor(1, 3)
print(vector.shape)
print(tensor.shape)
# tensor 对比 Tensor
empty_tensor = t.tensor([])
empty_Tensor = t.Tensor([])
empty_tensor.shape == empty_Tensor.shape<jupyter_output><empty_output><jupyter_text>tensor维度操作：view、squeeze、unsqueeze、resize(可超过、少于本tensor的维度)  非inplace操作,对应的 xxx_()为inplace操作<jupyter_code>a = torch.arange(0, 4)
b = a.view(-1, 2)           # view、unsqueeze非inplace操作
b.shape
b.shape
c = b.unsqueeze(2)
c.shape     # 在位置1处增加了一维（0/1/2）
b = a.unsqueeze(0).shape<jupyter_output>torch.Size([1, 4])
{'fraction_non_alphanumeric': 0.17768199233716475, 'fraction_numerical': 0.04310344827586207, 'mean_word_length': 3.880841121495327, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '5293', 'license': 'MIT', 'n_tokens_mistral': 988, 'n_tokens_neox': 982, 'n_words': 166, 'path': 'pytorch-Learning/firstTry.ipynb', 'repo_name': 'GalileoSama/MachineLearning', 'size': '2088'}