1
我有一个大小为mxn的矩阵M和mx为1的列向量。 对于m行中的每一行,我需要拾取对应于列向量中的值的索引减1。因此,给我答案mx 1.我该怎么做?通过列向量对矩阵进行索引
zb=a1.a3[np.arange(a1.z3.shape[0]),a1.train_labels-1]
zb.shape
Out[72]: (4000, 4000)
a1.z3.shape
Out[73]: (4000, 26)
a1.train_labels.shape
Out[74]: (4000, 1)
a1.train_labels.head()
Out[75]:
22
1618 25
2330 1
1651 17
133 17
2360 5
#my column vector a1.train_labels is shuffled. I don't want to unshuffle it.
它不能作为工作在我的例子中显示。尝试洗牌列向量'random_perm = np.random.permutation(data_size)train_labels = train_labels.iloc [random_perm]' –
@AbhishekBhatia在我的例子它使用'np.random.permutation'后,所以我认为问题是在哪里你正在把这些东西变成'numpy'数组(从那里看起来工作起来)。你可以发布你正在得到的确切的错误信息,还是一些最小的独立示例? (最好是两者)。 –