2016-05-11 7 views
0

私はこのエラーを取得する:Pythonの:私は私のスクリプトを実行するとはAttributeError

File "test_cm.py", line 34, in

labels = labels_img.get_data() AttributeError: 'tuple' object has no attribute 'get_data'

from dipy.tracking.eudx import EuDX 
from dipy.reconst import peaks, shm 
from dipy.tracking import utils 
from dipy.data import read_stanford_labels 
from dipy.io.gradients import read_bvals_bvecs 

import numpy as np 
import matplotlib.pyplot as plt 
import nibabel as nib 

source="prova11/" 
path=source 

print('loading data') 
bvals,bvecs=read_bvals_bvecs(source+"bvals",source+"bvecs") 
bvals[bvals < 10] = 0 
img = nib.load(source+"segment-TO-b0.nii") 
data = img.get_data() 
affine=img.affine 
labels_img = read_stanford_labels() 
labels = labels_img.get_data() 

答えて

0

read_stanford_labels()はタプルを返し、タプルは、エラーがAttributeError: 'tuple' object has no attribute 'get_data'を言う理由ですget_data()メソッドを持っていません。

あなたのread_stanford_labels関数を調べて、それが期待したものではないタプルを返す理由を調べるべきです。

編集:documentation/exampleあなたのコードの上に行くことは
hardi_img, gtab, labels_img = read_stanford_labels()代わりの labels_img = read_stanford_labels()
でなければなりません。あなたが最初の2つの値を必要としない場合

あるいは、あなたは
labels_img = read_stanford_labels()[-1]または
*_, labels_img = read_stanford_labels()を使用することができます。

関連する問題