tensorflow断言元素tf.where

时间:2018-05-07 08:54:43

标签: tensorflow z-index

我有2个形状矩阵:

pob.shape = (2,49,20)  
rob.shape = np.zeros((2,49,20))  

我希望获得pob元素的索引值!= 0。所以在numpy我能做到这一点:

x,y,z = np.where(pob!=0)

例如:

x = [2,4,7]  
y = [3,5,5]  
z = [3,5,6]

我想更改rob的值:

rob[x1,y1,:] = np.ones((20))

我如何使用tensorflow对象执行此操作? 我试图使用tf.where但我无法从张量obj中获取索引值

1 个答案:

答案 0 :(得分:0)

您可以使用 body { background-color: #444444; font-family: 'Didact Gothic', sans-serif; font-family: 'Lato', sans-serif; font-size: 18px; color: white; } #container { margin-left: auto; margin-right: auto; width: 1000px; } #logo { text-align: center; padding: 15px; background-color: #303030; color: white; font-size: 30px; font-weight: 900; margin-bottom: 30px; } #navbar { background-color: black; margin-top: 20px; padding: 10px; } .click { float: left; margin-left: 20px; } .click:hover { cursor: pointer; background-color: green; } #quote { height: 230px; width: 980px; padding: 10px; background-color: red; margin-top: 20px; margin-bottom: 25px; } #quoteL { float: left; width: 180px; height: 180px; } #quoteR { float: left; width: 800px; font-size: 16px; text-align: justify; } #quoteL img{ height: 210px;} .bigtitle { font-size: 32px; font-weight: 900; letter-spacing: 2px; display: block; } <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>Angielski - Nauka angielskiego dla zainteresowanych</title> <meta name="keywords" content="angielski, English, english, nauka angielskiego, angielskiego, nauka, online, nauka angielskiego online, efektywna nauka, prosta gramatyka, gramatyka, słownictwo, tłumaczenie, pomoc, jak" /> <meta name="description" content="Ta strona pomoże ci nauczyć się angielskiego w wolnym czasie bez problemu i z przyjemnością!" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <link rel="stylesheet" href="style.css" type="text/css" /> <link href="https://fonts.googleapis.com/css?family=Didact+Gothic|Lato:400,400i,700,900&amp;subset=latin-ext" rel="stylesheet"> </head> <body> <div id="container"> <div id="logo">English 4 Everyone :D</div> <div id="navbar"> <div class="click">TO BE</div> <div class="click">TO HAVE/TO HAVE GOT</div> <div class="click">PRESENT SIMPLE</div> <div style="clear:both;"></div> </div> <div id="quote"> <div id="quoteL"> <img src="https://i.stack.imgur.com/8hZeG.jpg" /> </div> <div id="quoteR"> <span class="bigtitle">Quote to success:</span> "Our job in grammar teaching is not to describe the language, as a grammarian does.It is to build a bridge from A (what the student knows) to B (what we want him/her to know next). If the bridge is too long it will collapse." ~Michael Swan source: https://mikeswan.net/some-things-i-believe/ </div> <div style="clear: both;"></div> </div> </div> </body> </html>创建索引矩阵,然后根据条件使用tf.range()来获取满足它的索引。然而,接下来会出现棘手的部分:您无法根据TF(tf.meshgrid())中的索引轻松地将值分配给张量。

针对您的问题的解决方法(&#34;对于所有tf.where(),如果my_tensor[my_indices] = my_values然后(i,j,k)&#34;)可以如下:

pob[i,j,k] != 0