是否正在填充如下的numpy数组:
import numpy as np
import bct as bct
mri_thresh = np.linspace(0.2, 0.07, 20)
W = np.random.rand(40,40)
W_bin = np.zeros([40, 40 , len(mri_thresh)])
i = 0
for thresh in mri_thresh:
W_bin[:, :, i] = (bct.threshold(W, thresh)>0)
i = i+1
似乎有一种更简洁的方法来实现相同的目的
W_bin = [(bct.threshold_proportional(W, thresh)>0 for thresh in mri_thresh)]
但是这里我有一个发电机。我的问题是,有没有办法让它产生一个numpy数组,而不是使用类似的代码生成器?