2014-11-05 152 views
0

我想用一個「for循環」來應用np.dot,但是出現一個錯誤:'tuple'對象沒有任何屬性'shape'出現......我有很棒的數組,對我來說這是對待我的問題的最佳方式。Python - np.dot for for循環

import numpy as np 

M = np.array([[ 1.15808013, 0.06208023, 4.05766652], 
     [ 0.00440335, 1.10580116, 2.19747653]]) 


test=np.array([[[ 1., 1., 2., 2.], 
     [ 1., 1., 2., 2.], 
     [ 3., 3., 4., 4.], 
     [ 3., 3., 4., 4.]], 

     [[ 5., 5., 6., 6.], 
     [ 5., 5., 6., 6.], 
     [ 7., 7., 8., 8.], 
     [ 7., 7., 8., 8.]], 

     [[ 1., 1., 1., 1.], 
     [ 1., 1., 1., 1.], 
     [ 1., 1., 1., 1.], 
     [ 1., 1., 1., 1.]]]) 

for i in range(test.shape[1]): 
    for j in range(test.shape[2]): 
     xtp = np.dot(M,test[:,i,j]) 
+2

我沒有得到你的例子錯誤。它工作正常 – freude 2014-11-05 16:04:06

+0

Python 2.7.3與NumPy 1.6.2沒有錯誤。你正在使用哪些版本? – 2014-11-05 16:05:00

+0

你可以發佈_full_追蹤? – mgilson 2014-11-05 16:05:12

回答

0

的答案,讓我所有的座標:

frametemp = [] 

for i in range(test.shape[1]): 
    for j in range(test.shape[2]): 
     xtp = np.dot(M,test[:,i,j]) 
     frametemp.append(xtp) 

frametemperature = np.asarray(frametemp)