簡體   English   中英

如何在張量流中的張量中執行項目分配?

[英]How to perform item assignment in a tensor in tensorflow?

假設張量為a = [0,0,0,0,0,0,0,0] ,另一個張量為b = [1,3,0,5] ,這里我想要一個張量流操作將1放入張量a從張量b獲得位置值。 因此,輸出張量將為[1,1,0,1,0,1,0,0] 如何解決這個問題呢?

那這個呢 ?

a = tf.Variable([0,0,0,0,0,0,0,0])
b = tf.Variable([1,3,0,5])

with tf.Session() as sess:

    sess.run(tf.global_variables_initializer())

    update = tf.scatter_update(a,
                               b,
                               tf.tile(tf.constant([1],
                                       tf.int32),
                               b.shape))

    print(update.eval(session=sess))

輸出是

[1 1 0 1 0 1 0 0]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM