美文网首页
np.array division

np.array division

作者: LF8313 | 来源:发表于2018-08-15 18:47 被阅读0次

    矩阵形式的范数归一设计到矩阵除法

    举个简单的例子:
    假设一个数据矩阵A规模为(4,3,2),可以理解为4个样本,每个样本是一个时间长度为3的点,点是(x, y)形式的二维空间的样本。

      > A = np.random.random((4,3,2))
      array([[[0.89239403, 0.12214923],
            [0.51232698, 0.15274605],
            [0.60971146, 0.07217262]],
    
           [[0.19267784, 0.11648302],
            [0.09225679, 0.95131037],
            [0.25777361, 0.23847847]],
    
           [[0.77162583, 0.05490807],
            [0.61026345, 0.1172357 ],
            [0.9613178 , 0.56668329]],
    
           [[0.8195157 , 0.44777402],
            [0.77027723, 0.90067652],
            [0.48683648, 0.80049979]]])
    

    记对每个(x, y)点求范数后的矩阵为B,即相应规模为(4,3,1)

    > B = np.random.random((4,3,1))
    array([[[0.79237377],
            [0.17657666],
            [0.06914004]],
    
           [[0.76301106],
            [0.4939386 ],
            [0.64676006]],
    
           [[0.73634844],
            [0.78604091],
            [0.14897835]],
    
           [[0.2775787 ],
            [0.69762266],
            [0.42144431]]])
    

    A/B的结果则为(x, y)的点除以相应范数的结果。

    > a/b
    array([[[1.12622865, 0.15415608],
            [2.90144227, 0.86504101],
            [8.8185003 , 1.04386148]],
    
           [[0.25252299, 0.1526623 ],
            [0.18677785, 1.92596887],
            [0.39856143, 0.36872789]],
    
           [[1.04790856, 0.07456805],
            [0.77637619, 0.14914707],
            [6.45273499, 3.80379628]],
    
           [[2.95237238, 1.61314255],
            [1.10414594, 1.29106545],
            [1.15516206, 1.89942009]]])
    

    验证

    > 0.89239403/0.79237377
    1.1262286357611258
    > 0.19267784/0.76301106
    0.2525229975041253
    > 0.12214923/0.79237377
    0.15415607460100553
    

    相关文章

      网友评论

          本文标题:np.array division

          本文链接:https://www.haomeiwen.com/subject/mttgbftx.html