0
t=0
abig= zeros((10000,150))    
aa=[0 for i in range(150)]
print abig[0]

while 1:
    aa=abig[t]

    for k in range(150):

        for i in range(150):         
            ppp=aa[k]+nk[k]*(1-iris[k][3]*aa[i]*iris[i][3]*kk[i][k])
        aa[k]=ppp

        if aa[k]<0:
            aa[k]=0
        if aa[k]>10:
            aa[k]=10
    print abig[0]
    abig[t+1]=aa
    t=t+1
    sds=subtract(abig[t-1],abig[t])
    if norm(sds)<0.0001:
        break
print t 
print aa

我的期望是将每个分配abig[t]给 aa,然后用 aa 进行一些计算,然后将 aa 分配回去,abig[t+1]然后得到这两者的减法。

但这是我的结果:

"D:\Python27\python.exe" "C:\Users\zlxstc\Desktop\数据库挖掘\assignment 3\Untitled 3.py" [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

[ 0.02182929 0.01688619 0.01852881 0.02994012 0.02334267 0.02912904 0.01877934 0.02329373 0.01769912 0.01881822 0.02398082 0.02355713 0.02299379 0.02074258 0.02807412 0.02593361 0.02593361 0.02362391 0.02639219 0.01560549 0.02182929 0.01877934 0.0185701 0.02597403 0.03099814 0.02547771 0.02663825 0.03051572 0.01591343 0.01709986 0.02156567 0.02685285 0.0245459 0.02358491 0.02918856 0.02524615 0.02329373 0.02355713 0.02128565 0.02085941 0.02360718 0.02074258 0.0174703 0.01569859 0.02460025 0.0293772 0.01628399 0.02424242 0.02284148 0.02043736 0.02331002 0.02427184 0.03293808 0.01901864 0.02340824 0.01877934 0.01688619 0.01422677 0.02125399 0.02394063 0.02175332 0.0199005 0.02547771 0.02570694 0.02360718 0.0249004 0.02299908 0.02807412 0.02768549 0.02463054 0.01268231 0.01469508 0.02125399 0.02247191 0.02880184 0.02912904 0.03359086 0.02071251 0.0293772 0.02154708 0.01923077 0.03096934 0.01879699 0.01996008 0.01789229 0.03225806 0.02125399 0.01730703 0.02156567 0.0204165 0.0273224 0.03164557 0.01879699 0.02208481 0.02334267 0.01547988 0.03147624 0.0163292 0.02630887 0.01901864 0.01783167 0.02099958 0.01835199 0.01730703 0.01769912 0.0273224 0.02856327 0.01670844 0.03631082 0.0339098 0.02752546 0.02502503 0.01946661 0.02421894 0.02329373 0.0200441 0.01454334 0.02018978 0.01902226 0.02085941 0.02329373 0.02777778 0.01769912 0.02207993 0.02483855 0.02886003 0.02362391 0.02355713 0.01832845 0.01968504 0.02181025 0.01968504 0.0144655 0.01936483 0.02807412 0.02229654 0.02483855 0.02017756 0.01877934 0.02630887 0.01497006 0.01688619 0.02047083 0.01919754 0.0212766 0.02340824 0.02563445 0.02563445 0.01789229 0.015716.......................20..........27

两者abig[0]不一样。所以减法是0。为什么?kk[]nk[]以上有一些定义iris[]。它们是否相关?

4

1 回答 1

2

您的代码中有几个问题(除了变量名的选择)。首先,做:

aa=abig[t]

不复制abig[t]. 相反aa,并且abig[t]引用相同的数据,因此如果您执行以下操作:

aa[1] = 20

然后自动

abig[t][1] = 20

另一方面,分配的顺序可能是错误的。我想你想要的是:

abig[t] = aa

abig似乎是一个numpy数组,该copy方法被隐式使用,因此它是abig[t]一个副本aa(它们不共享数据)。

现在做:

abig[t][1] = 20

没有改变aa[1]

其次,这部分代码:

for i in range(150):         
    ppp=aa[k]+nk[k]*(1-iris[k][3]*aa[i]*iris[i][3]*kk[i][k])
aa[k]=ppp

与以下内容相同:

aa[k]=aa[k]+nk[k]*(1-iris[k][3]*aa[149]*iris[149][3]*kk[149][k])

所以循环是没用的。我想你真正的意思是

for i in range(150):         
    aa[k]=aa[k]+nk[k]*(1-iris[k][3]*aa[i]*iris[i][3]*kk[i][k])

(但不完全确定)。

总之,在您当前的实现aa中,abig[t]并且abig[t+1]都引用相同的数据,因此当您减去连续的行时,您会得到一堆零。

于 2012-10-20T01:26:44.347 回答