我有这个功能:
def change_position(old_particles):
inc_r=0.5
inc_angle=0.5
N=len(old_particles)
particlesx=old_particles
a=random.randint(0,N-1)
b=random.randint(0,1)
max_angle=np.pi*2
c=random.randint(0,1)
print 'old_particles before change', old_particles
print 'new before change', particlesx
if b==1:
if c==1:
particlesx[a][b]=particlesx[a][b]+inc_angle
if particlesx[a][b]>max_angle:
particlesx[a][b]=particlesx[a][b]-max_angle
print 'cambiamos particula',a, particlesx[a][b]
if b==1:
if c==0:
particlesx[a][b]=particlesx[a][b]-inc_angle
if particlesx[a][b]<0:
particlesx[a][b]=particlesx[a][b]+max_angle
print 'cambiamos',a, particlesx[a][b]
if b==0:
if c==0:
particlesx[a][b]=particlesx[a][b]+inc_r
if particlesx[a][b]>1:
particlesx[a][b]=particlesx[a][b]-inc_r
print 'cambiamos',a, particlesx[a][b]
if b==0:
if c==1:
particlesx[a][b]=particlesx[a][b]-inc_r
if particlesx[a][b]<0:
particlesx[a][b]=particlesx[a][b]+inc_r
print 'cambiamos',a, particlesx[a][b]
print'after change', particlesx
print'old_particles after change', old_particles
return particlesx, a
问题是由于我不明白的原因,该函数不仅改变了“particlesx”的值,还改变了 old_particles 的值,因此脚本末尾的两个数组的值不仅在函数中而且在函数之外。谁能帮我这个?谢谢!