import numpy as np
aa=np.full((3, 3), 99)
print('aa',aa)
ffx=1234
def ff():
a=100
b=200
c=300
dd=np.full((2, 2), np.inf)
ee=aa[1:3,0:2]
global ffx # 說明這個變數是global variable
kk=ffx
ffx=np.copy(ee) # 建立一個copy (allocated)
ee[0,0]=88
ffx[0,1]=77
print ('e',ee,'ffx',ffx)
print("kkk",kk)
return (a,b,c,dd[1:2,0:1],ee,ffx)
x,y,z,ddd,eee,ffz =ff()
print('x',x,'y',y,'z',z,'ddd',ddd,'eee',eee)
eee[1,0]=66 # eee 與 aa是同一個reference
ffz[0,1]=22
print ('aa',aa,'eee',eee,'ffz',ffz,ffx) #ffz, ffx 是同個內容, 只有一套
---
aa [[99 99 99]
[99 99 99]
[99 99 99]]
e [[88 99]
[99 99]] ffx [[99 77]
[99 99]]
kkk 1234
x 100 y 200 z 300 ddd [[inf]] eee [[88 99]
[99 99]]
aa [[99 99 99]
[88 99 99]
[66 99 99]] eee [[88 99]
[66 99]] ffz [[99 22]
[99 99]] [[99 22]
[99 99]]
留言列表