tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT')
tf.pad 是扩展的意思,其中[0, 0], [1, 0] 分别代表的是[上,下][左,右] 值为0代表相应边扩展0,比如上面代码中,左的位置的值为0,代表在左边增加一列,填充是mode='CONSTANT',代表用0填充,具体见:
https://www.tensorflow.org/api_docs/python/tf/pad
# 't' is [[1, 2, 3], [4, 5, 6]]. # 'paddings' is [[1, 1,], [2, 2]]. # 'constant_values' is 0. # rank of 't' is 2. pad(t, paddings, "CONSTANT") ==> [[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 0, 0], [0, 0, 4, 5, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0]] pad(t, paddings, "REFLECT") ==> [[6, 5, 4, 5, 6, 5, 4], [3, 2, 1, 2, 3, 2, 1], [6, 5, 4, 5, 6, 5, 4], [3, 2, 1, 2, 3, 2, 1]]pad(t, paddings, "SYMMETRIC") ==> [[2, 1, 1, 2, 3, 3, 2], [2, 1, 1, 2, 3, 3, 2], [5, 4, 4, 5, 6, 6, 5], [5, 4, 4, 5, 6, 6, 5]]