+= acts in place to modify an existing array rather than create a new one.
a = ones((2,3),dtype = int) # a 是 int32
array([[1, 1, 1],
[1, 1, 1]])
b = random.random((2,3)) # b是float64
array([[ 0.43400905, 0.12813364, 0.07011925],
[ 0.71473968, 0.27888818, 0.58019516]])
a = a + b # a现在是float64, a现在指向一个新的array
array([[ 1.43400905, 1.12813364, 1.07011925],
[ 1.71473968, 1.27888818, 1.58019516]])
a += b # a 还是原来的array , 类型还是int32
array([[1, 1, 1],
[1, 1, 1]])
+=或者其他类似的操作(*=) 是改变原来的对象。
原文地址:http://blog.csdn.net/xiaochaoqu/article/details/42646069