【发布时间】:2014-06-28 14:05:04
【问题描述】:
我有 numpy 数组,名为 data,维度为 150x4
我想通过从data 中选择随机元素来创建一个名为mean 的新numpy 数组,其维度为3x4。
我目前的实现是:
cols = (data.shape[1])
K=3
mean = np.zeros((K,cols))
for row in range(K):
index = np.random.randint(data.shape[0])
for col in range(cols):
mean[row][col] = data[index][col]
有没有更快的方法来做同样的事情?
【问题讨论】:
标签: python python-2.7 python-3.x numpy scipy