Numpy广播

2018-07-28  本文已影响0人  哈哈哈哈_ad14
  1. If the arrays do not have the same rank, prepend the shape of the lower rank array with 1s until both shapes have the same length.
  2. The two arrays are said to be compatible in a dimension if they have the same size in the dimension, or if one of the arrays has size 1 in that dimension.
  3. The arrays can be broadcast together if they are compatible in all dimensions.
  4. After broadcasting, each array behaves as if it had shape equal to the elementwise maximum of shapes of the two input arrays.
  5. In any dimension where one array had size 1 and the other array had size greater than 1, the first array behaves as if it were copied along that dimension
  1. b的维度小于a, 因此首先增加维度对齐,b.shape变成(1,),
  2. 然后b再在维度为1上tail变成(3,)
  3. 两个shape相同的array最后相加.最后的shape也是(3,0)
    ps:如果按照原文说的,最后的shape将是(3,1),这个可以自己实验一下
上一篇 下一篇

猜你喜欢

热点阅读