基础的RNN
作者:互联网
import tensorflow as tf import numpy as np n_input=3 n_neurons=5 x0=tf.placeholder(tf.float32,[None,n_input]) x1=tf.placeholder(tf.float32,[None,n_input]) wx=tf.Variable(tf.random_normal(shape=[n_input,n_neurons],dtype=tf.float32)) wy=tf.Variable(tf.random_normal(shape=[n_neurons,n_neurons],dtype=tf.float32)) b=tf.Variable(tf.zeros([1,n_neurons],dtype=tf.float32)) y0=tf.tanh(tf.matmul(x0,wx)+b) y1=tf.tanh(tf.matmul(y0,wy)+tf.matmul(x1,wx)+b) init=tf.global_variables_initializer() x0_batch=np.array([[0,1,2],[3,4,5],[6,7,8],[9,0,1]]) x1_batch=np.array([[9,8,7],[0,0,0],[6,5,4],[3,2,1]]) with tf.Session() as sess: init.run() yo_val,y2_val=sess.run([y0,y1],feed_dict={x0:x0_batch,x1:x1_batch}) print(yo_val) print('---------') print(y2_val)
标签:RNN,基础,neurons,tf,input,x0,x1,float32 来源: https://blog.51cto.com/u_14540820/2759446