java 线性计算_计算线性指数Tensorflow
下午好 . 我繼續(xù)遇到通過索引更新張量流中的隨機元素的問題 . 我想隨機選擇索引(例如,一半),然后設(shè)置為零元素對應(yīng)于那些索引 . 這是有問題的部分:
with tf.variable_scope("foo", reuse=True):
temp_var = tf.get_variable("W")
size_2a = tf.get_variable("b")
s1 = tf.shape(temp_var).eval()[0]
s2 = tf.shape(size_2a).eval()[0]
row_indices = tf.random_uniform(dtype=tf.int32, minval=0, maxval = s1 - 1, shape=[s1]).eval()
col_indices = tf.random_uniform(dtype=tf.int32, minval=0, maxval = s2 - 1, shape=[s2]).eval()
ones_mask = tf.ones([s1,s2])
# turn 'ones_mask' into 1d variable since "scatter_update" supports linear indexing only
ones_flat = tf.Variable(tf.reshape(ones_mask, [-1]))
# no automatic promotion, so make updates float32 to match ones_mask
updates = tf.zeros(shape=(s1,), dtype=tf.float32)
# get linear indices
linear_indices = row_indices*s2 + tf.reshape(col_indices,s1*s2)
ones_flat = tf.scatter_update(ones_flat, linear_indices/2, updates)
#I want to set to zero only half of all elements,that's why linear_indices/2
# convert back into original shape
ones_mask = tf.reshape(ones_flat, ones_mask.get_shape())
它給了我ValueError:不能用10個元素重塑一個張量來為'foo_1 / Reshape_1'(op:'Reshape')塑造[784,10](7840個元素)輸入形狀:[10],[2] . 但是我不知道如何在沒有重塑的情況下來到這里(我試圖重塑s1和s2,沒有用)
總結(jié)
以上是生活随笔為你收集整理的java 线性计算_计算线性指数Tensorflow的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux地柜查找文件_linux-fi
- 下一篇: java pdf添加透明水印_如何在PD