2021年4月25日
摘要: 最小值点有4个 import numpy as np from mpl_toolkits.mplot3d import Axes3D from matplotlib import pyplot as plt import torch def himmelblau(x): return (x[0] * 阅读全文
posted @ 2021-04-25 22:12 一抹烟霞 阅读(120) 评论(0) 推荐(0)
摘要: @ 声明需要进行自动梯度 未申明的变量将无法进行自动梯度 申明方法有两种 # 在创建完成后,申明自动梯度 x = torch.ones(1) x.requires_grad() # 在创建时,就申明自动梯度 w = torch.full([1],2,requires_grad=True) 进行自动梯 阅读全文
posted @ 2021-04-25 21:24 一抹烟霞 阅读(141) 评论(0) 推荐(0)
摘要: where() 条件判断 gather()查表 input :待查的表 dim : 在input的哪个维度上查表 index: 待查表的索引值 阅读全文
posted @ 2021-04-25 21:01 一抹烟霞 阅读(621) 评论(0) 推荐(0)
摘要: @ 矩阵乘法 只对2d矩阵有效,因为矩阵乘法是定义在2d矩阵上的 torch.mm(a,b) torch.matmul(a,b) a@b tensor的幂 对tensor中的每一个元素都进行幂运算 exp()/log() 近似运算 clamp() 截断 将小于10的都等于10 将大于10的都等于10 阅读全文
posted @ 2021-04-25 20:31 一抹烟霞 阅读(564) 评论(0) 推荐(0)
摘要: @ 维度变换 view()/reshape() 改变形状 view()/reshape()等价,参数为需要目标tensor的形状 unsqueeze()增加维度 在指定位置增加一个维度,参数为增加后,被增加维度所在的位置索引 squeeze()压缩维度 只能压缩长度为1的维度,参数为压缩前,被压缩维 阅读全文
posted @ 2021-04-25 20:01 一抹烟霞 阅读(208) 评论(0) 推荐(0)
摘要: @ torch.tensor() 直接使用数据构造张量 a = torch.tensor(5.5) # 构造dim=0的标量 a = torch.tensor([5.5]) # 构造dim=1 的向量 b = torch.tensor([5.5, 3]) torch.FloatTensor() # 阅读全文
posted @ 2021-04-25 16:59 一抹烟霞 阅读(295) 评论(0) 推荐(0)

Live2D