2017-06-19 99 views
1

近日,筆者從tensorflow.Part代碼如下教程在https://www.tensorflow.org/tutorials/recurrent如何理解tensorflow的切片功能?

outputs = [] 
    state = self._initial_state 
    with tf.variable_scope("RNN"): 
     for time_step in range(num_steps): 
     if time_step > 0: tf.get_variable_scope().reuse_variables() 
     (cell_output, state) = cell(inputs[:, time_step, :], state)#here! 
     outputs.append(cell_output) 

瞭解RNN的代碼,而更多的信息,我只是不能說undetstand如何inputs[:, time_step, :]作品,例如,這些Args是什麼意思? 您的回答將不勝感激。非常感謝!

回答

0

如果input是形狀[d1, d2, d3]的,time_step低於d2的自然數,並且

output = inputs[:, time_step, :] 

然後輸出形狀的矩陣[d1, 1, d3]使得

output[i, 0, j] = input[i, time_step, j] 

它基本上提取的元素由括號中給出的指數給出的輸入,「:」含義「所有這些都在該維度上」

+1

非常感謝!你讓我擺脫困惑。 – chuchienshu

+0

對不起,我只是一個初學者到StackOverFlow,並且我只點擊了上拉(沒有顯示,因爲我的名聲低於15)。現在,接受。謝謝 – chuchienshu