【发布时间】:2018-07-23 19:24:52
【问题描述】:
我在 jupyter notebook 上使用 python 3.6。
我写了这段代码来可视化一些数据。
from nilearn import plotting
DMN = plotting.plot_glass_brain("/Users/projets/rmap_seeds/average_rmap_DMN.nii.gz",
draw_cross = True, colorbar=True)
plt.show()
我有很多不同的文件想要可视化
我想做一个 for 循环,所以我不必手动编写它们。我这里只是举了两个例子,但实际上我有数百个。
我试过了:
image = {'average_rmap_DMN', 'average_rmap_CER'}
for i in image :
image(i) = plotting.plot_glass_brain("/Users/projets/rmap_seeds/",
(image{i}), ".nii.gz", draw_cross = True, colorbar=True, threshold=0.7)
我得到这个错误:
SyntaxError: invalid syntax
谢谢!
【问题讨论】:
-
您在
image(i) = plotting.plot_glass_brain...这一行收到此错误? -
请查看如何创建和访问列表——您已创建字典但访问不正确
-
此问题与您要完成的任务无关。
image(i)尝试将image作为函数调用(给SyntaxError: can't assign to function call,而(image{i})试图用一组索引(我猜;这就是我在心理上解析它的方式,但我不知道它的确切路线成为语法错误)。[i]是用于索引的语法。 -
我将其更改为 [],现在我收到此错误:
TypeError: list indices must be integers or slices, not str -
@bim1,我的回答部分解决了该错误。你还有问题吗?