How do you select the same feature columns for every sample?

take gathers specified indices along an axis. Their order sets output order, and an index may appear more than once.

numpy.take in practice

Request column three followed by column one and every row comes back in that order. Omitting axis gathers from the flattened input.

import numpy as np
np.take([[2,4,6],[3,5,7]], [2,0], axis=1)

Result [[6, 2], [7, 3]]

中文

如何给每个样本抽取同一组特征列?

take 按给定索引沿指定轴取值。索引的排列决定结果的排列,可以重复选择。

numpy.take 算例

从每行取第 3 列再取第 1 列,结果按这个新顺序排列。省略 axis 会先把输入视为展平序列。

import numpy as np
np.take([[2,4,6],[3,5,7]], [2,0], axis=1)

结果 [[6, 2], [7, 3]]

References / 参考来源

Keep reading / 继续阅读