- torch.norm() 求范数函数,p参数为指明0 1 2范数,dim参数为指明矩阵范数还是矢量范数
- torch.clamp() 限制张量范围上下限
- torch.prod(input, dim, keepdim=False, dtype=None) → Tensor
Returns the product of each row of the input tensor in the given dimension dim.
dim 要减少的维度
keepdim (bool) – whether the output tensor has dim retained or not. - torch.where(condition, x, y) → Tensor
Return a tensor of elements selected from either x or y, depending on condition.
如何使用Dataloader加载自己的数据集
详细请点击这里
1.自己创建的数据集类首先继承Dataset类,然后在类里重写两个函数:
def __getitem__(self, index):
def __len__(self):
2.自定义一个collate_fn函数,传入DataLoader里面
def collate_fn(batch):
LSTM实践与理论结合:
在单层单向LSTM中,其outputs其实就是每一个timestep产生的h_t拼接起来的,而h_n则是LSTM最后h_t,其中outputs[-1,:,:] 就等于h_n[-1,:,:]
python日志模块logging的用法
seed() 和torch中manual_seed的作用
python中的几种矩阵乘法 np.dot, np.multiply, *
np.dot() :对于二维矩阵,计算真正意义上的矩阵乘积,同线性代数中矩阵乘法的定义。对于一维矩阵,计算两者的内积。
np.multiply(), 或 * : element-wise product. 实现对应元素相乘,有2种方式,一个是np.multiply(),另外一个是*。
具体示例请参考此博客