先给出一个样例看看
import tensorflow as tf
raw = tf.constant([1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1])
'''
拆成 [1,2] [3,4] [5,6] [6,5] [4,3] [2,1]
'''
result_1 = tf.dynamic_partition(tf.reshape(raw, [6,2]),[0, 1, 2, 3, 4, 5], 6)
'''
拆成 [1, 2, 3, 4, 5, 6] [6, 5, 4, 3, 2, 1]
'''
result_2 = tf.dynamic_partition(tf.reshape(raw, [2, 6]), [0, 1], 2)
'''
拆成 [1] [2] [3] [4] [5] [6] [6] [5] [4] [3] [2] [1]
'''
result_3 = tf.dynamic_partition(tf.reshape(raw, [12, 1]), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 12)
with tf.Session() as sess:
print(sess.run(result_1))
print(sess.run(result_2))
print(sess.run(result_3))
结果
[array([[1, 2]]), array([[3, 4]]), array([[5, 6]]), array([[6, 5]]), array([[4, 3]]), array([[2, 1]])]
[array(