tf.dynamic_stitch 和 tf.dynamic_partition
生活随笔
收集整理的這篇文章主要介紹了
tf.dynamic_stitch 和 tf.dynamic_partition
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import tensorflow as tf
x=tf.constant([0.1, -1., 5.2, 4.3, -1., 7.4])#判斷x里面的元素是否是1
condition_mask=tf.not_equal(x,tf.constant(-1.))#[ True, False, True, True, False, True]#將張量拆成兩個,按照condition_mask的對應位置
partitioned_data = tf.dynamic_partition(x, tf.cast(condition_mask, tf.int32) , 2)#partitioned_data[0]=[-1., -1.]
#partitioned_data[1]=[2.1, 7.2, 6.3, 9.4]partitioned_data[1] = partitioned_data[1] + 1.0#這行代碼是提取索引位置
condition_indices = tf.dynamic_partition(tf.range(tf.shape(x)[0]), tf.cast(condition_mask, tf.int32) , 2)x = tf.dynamic_stitch(condition_indices, partitioned_data)
# Here x=[1.1, -1., 6.2, 5.3, -1, 8.4], the -1. values remain
# unchanged.
總結
以上是生活随笔為你收集整理的tf.dynamic_stitch 和 tf.dynamic_partition的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BP神经网络python代码详细解答(来
- 下一篇: tf.sparse.SparseTens