美文网首页
repeat tensorflow in different w

repeat tensorflow in different w

作者: 昵称己存在 | 来源:发表于2018-07-11 09:59 被阅读0次

1. Repeat block by block

In [33]: prior.eval()
Out[33]:
array([[0, 0, 0, 0],
       [0, 1, 0, 0],
       [1, 0, 0, 0],
       [1, 1, 0, 0]], dtype=int32)

In [34]: p1 = tf.tile(prior, [3,1])

In [35]: p1.eval()
Out[35]:
array([[0, 0, 0, 0],
       [0, 1, 0, 0],
       [1, 0, 0, 0],
       [1, 1, 0, 0],
       [0, 0, 0, 0],
       [0, 1, 0, 0],
       [1, 0, 0, 0],
       [1, 1, 0, 0],
       [0, 0, 0, 0],
       [0, 1, 0, 0],
       [1, 0, 0, 0],
       [1, 1, 0, 0]], dtype=int32)

2. Repeat element by element

In [63]: a.eval()
Out[63]:
array([[0, 0, 0, 0],
       [0, 1, 0, 0],
       [1, 0, 0, 0],
       [1, 1, 0, 0]], dtype=int32)

In [64]: a.get_shape().as_list()
Out[64]: [4, 4]

In [65]: a1 = tf.expand_dims(a, 1)

In [66]: a2 = tf.tile(a1, [1, 2, 1])

In [67]: a2.eval()
Out[67]:
array([[[0, 0, 0, 0],
        [0, 0, 0, 0]],

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

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

       [[1, 1, 0, 0],
        [1, 1, 0, 0]]], dtype=int32)

In [68]: result = tf.reshape(a2, [-1, 4])

In [69]: result.eval()
Out[69]:
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 1, 0, 0],
       [0, 1, 0, 0],
       [1, 0, 0, 0],
       [1, 0, 0, 0],
       [1, 1, 0, 0],
       [1, 1, 0, 0]], dtype=int32)

相关文章

网友评论

      本文标题:repeat tensorflow in different w

      本文链接:https://www.haomeiwen.com/subject/gcgcpftx.html