Broadcasting
A set of arrays is called “broadcastable” to the same shape if one of the following is true:
1.The arrays all have exactly the same shape.
2.The arrays all have the same number of dimensions and the length of each dimensions is either a common length or 1.
3.The arrays that have too few dimensions can have their shapes prepended with a dimension of length 1 to satisfy property 2.
上面三个条件从上到下条件越来越弱
另外关于数组的维数,要注意一维数组与行向量,列向量的区别,行向量与列向量是二维数组,只是其中的一个维数大小为1,其构建方式与一维数组也不同,[1,2]为一维数组(2,),[[1,2]]是行向量(1,2),[[1],[2]]是列向量(2,1)。用numpy.dot()函数进行数组点乘时,一维数组既可以当做行向量也可作为列向量。如:
a=[1,2], b=[[1,2],[3,4]]
c=dot(a,b)
output:[7,10]
c=dot(b,a)
output:[5,11]