Advertisement

pytorch中的归约函数包括norm、argmax、argmin、topk和kthvalue此外包含比较操作

阅读量:
复制代码
    import torch

norm 范数

||x||p = (||x1||p + ||x2||p + … + ||x3||p)1/p

  • 1范数:各元素绝对值之和
  • 2范数:各元素平方后的总和再开平方根
  • ∞范数:各元素取其绝对值后的最大者
复制代码
    a = torch.randint(-10,11,[2,3,2])
    a = a.to(torch.float64)
    a
复制代码
    tensor([[[ -7.,  -5.],
         [  6.,  -5.],
         [ -1.,  10.]],
    
        [[-10.,  -9.],
         [ -5.,  -4.],
         [ -8.,   2.]]], dtype=torch.float64)
复制代码
    a.norm(1)
复制代码
    tensor(72., dtype=torch.float64)
复制代码
    a.norm(2)
复制代码
    tensor(22.9347, dtype=torch.float64)
  • norm带有dim的情况:

  • 假设X为一个维度为I×J×K的数据结构,则其中每个元

全部评论 (0)

还没有任何评论哟~