ch6.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:aiw-second-edition 作者: dougmcilwraith 项目源码 文件源码
def nudge_dataset(X, Y):
    """
    This produces a dataset 5 times bigger than the original one,
    by moving the 8x8 images in X around by 1px to left, right, down, up
    """
    direction_vectors = [[[0, 1, 0],[0, 0, 0],[0, 0, 0]],
            [[0, 0, 0],[1, 0, 0],[0, 0, 0]],
            [[0, 0, 0],[0, 0, 1],[0, 0, 0]],
            [[0, 0, 0],[0, 0, 0],[0, 1, 0]]]
    shift = lambda x, w: convolve(x.reshape((8, 8)), mode='constant', weights=w).ravel()
    X = np.concatenate([X] + [np.apply_along_axis(shift, 1, X, vector) for vector in direction_vectors])
    Y = np.concatenate([Y for _ in range(5)], axis=0)
    return X, Y

#6.11
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号