How do you build a linear map that passes each feature through?

eye creates a two-dimensional array with ones on a selected diagonal. With a square shape and the main diagonal it is the identity.

numpy.eye in practice

A three-feature layer can use an identity matrix as a pass-through fixture. Setting k to one moves the ones above the diagonal and changes the mapping.

import numpy as np
np.eye(3, dtype=int)

Result [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

中文

怎样创建只保留对应特征的线性映射?

eye 创建对角线上为一、其他位置为零的二维数组。正方形主对角形式为单位矩阵。

numpy.eye 算例

在三个特征的变换层中,单位矩阵可当作直通测试夹具。将 k 设为 1 会把一移到上对角线,直通性质随之消失。

import numpy as np
np.eye(3, dtype=int)

结果 [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

References / 参考来源

Keep reading / 继续阅读