Numpy array broadcasting rules

后端 未结 2 1872
迷失自我
迷失自我 2020-12-14 07:47

I\'m having some trouble understanding the rules for array broadcasting in Numpy.

Obviously, if you perform element-wise multiplication on two arrays of the same dim

2条回答
  •  独厮守ぢ
    2020-12-14 07:59

    Well, the meaning of trailing axes is explained on the linked documentation page. If you have two arrays with different dimensions number, say one 1x2x3 and other 2x3, then you compare only the trailing common dimensions, in this case 2x3. But if both your arrays are two-dimensional, then their corresponding sizes have to be either equal or one of them has to be 1. Dimensions along which the array has size 1 are called singular, and the array can be broadcasted along them.

    In your case you have a 2x2 and 4x2 and 4 != 2 and neither 4 or 2 equals 1, so this doesn't work.

提交回复
热议问题