摘要: 结论:使用方法 # gather,沿dim指定的轴收集值。 y_hat.gather(1, y.view(-1, 1))# y.view(-1, 1)会变成一列,y_hat的取y作为的索引的值 分步理解:先创建一个2*3的tensor >>y_hat = torch.tensor([[0.1, 0. 阅读全文
posted @ 2021-01-19 20:48 zpcode 阅读(61) 评论(0) 推荐(0)
摘要: 本文记录如何实现softmax运算。 线性回归模型适用于输出为连续值的情景 softmax运算使输出更适合离散值的预测和训练 softmax用于分类问题: 预备知识:首先我们看看这个关于Tensor的运算:sum()函数 >>X = torch.tensor([1, 2, 3]) tensor([1 阅读全文
posted @ 2021-01-19 20:10 zpcode 阅读(94) 评论(0) 推荐(0)
摘要: 练习pytorch,记录自己的理解,好记性不如烂笔头! 第一步:生成数据集: num_inputs = 2 num_examples = 1000 true_w = [2, -3.4] true_b = 4.2 features = torch.tensor(np.random.normal(0, 阅读全文
posted @ 2021-01-19 13:53 zpcode 阅读(34) 评论(0) 推荐(0)