【发布时间】:2020-08-09 17:45:53
【问题描述】:
我试图获得一个大小为 235x20 的二维数组,这样对于 235 个 ROI 中的每一个,我根据存储在 find_bootstrap_indices 中的索引提取 20 个元素并将它们保存在 extract_bootstrap_timepoint 中。现在,我想将每个 ROI 的值及其对应的 20 个元素存储在一个数组中。我试图通过这条线new[roi][timepoint] = extract_bootstrap[timepoint] 来做到这一点,但我遇到了索引超出范围错误。任何有关如何解决此问题的帮助将不胜感激。谢谢。
new = []
for roi in range(0, rsfMRI_timeseries_2d.shape[0]):
extract_bootstrap_timepoint = np.take(rsfMRI_timeseries_2d[roi, :], find_bootstrap_indices)
for timepoint in range(0, len(extract_bootstrap_timepoint)):
new[roi][timepoint] = extract_bootstrap_timepoint[timepoint]
【问题讨论】:
-
您需要在分配给它之前创建
new[roi]列表。喜欢new[roi] = []
标签: python numpy loops indexing