numpy的append之后,为何没有变化 np.append(a,b)之后 print(a),会发现a与以前没有变化,代码如下:
import numpy as np
a=np.arange(0,10)
print('a=%s'%a)
b=np.arange(10,13)
print('b={}'.format(b))
c=np.append(a,b)
print('a=%s'%a)
print('c={}'.format(c))
-------->>>>> 结果如下: a=[0 1 2 3 4 5 6 7 8 9] b=[10 11 12] a=[0 1 2 3 4 5 6 7 8 9] c=[ 0 1 2 3 4 5 6 7 8 9 10 11 12]
原因: Note that append does not occur in-place: a new array is allocated and filled Append values to the end of an array. 解决办法: 为append赋予新的名称