cs231n-softmax-note


import numpy as np
np.log(10)
2.302585092994046
np.exp([1,2])
array([2.71828183, 7.3890561 ])

比较下列的异同,通常broadcasting是吧 (n,)这种类型的当成是行向量,而 concatenate 是当成列向量

a = np.array([[1,2,3,4],[3,4,5,6],[6,7,8,9]])
b = np.array([1,2,3])
a / b
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-9-b45cc87bf76c> in <module>()
      1 a = np.array([[1,2,3,4],[3,4,5,6],[6,7,8,9]])
      2 b = np.array([1,2,3])
----> 3 a / b


ValueError: operands could not be broadcast together with shapes (3,4) (3,) 
a = np.array([[1,2,3],[3,4,5],[6,7,8]])
b = np.array([1,2,3])
a / b
array([[1.        , 1.        , 1.        ],
       [3.        , 2.        , 1.66666667],
       [6.        , 3.5       , 2.66666667]])
a = np.array([[1,2,3],[3,4,5],[6,7,8]])
b = np.array([1,2,3])
b = b.reshape(-1,1)
a / b
array([[1.        , 2.        , 3.        ],
       [1.5       , 2.        , 2.5       ],
       [2.        , 2.33333333, 2.66666667]])

文章作者: lovelyfrog
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 lovelyfrog !
  目录