python - Tensorflow - Handling inputs to graph -


background:

i trying multiply tensor of size m tensor of size m. want result mxn tensor

for example:

1.0                       0.2    0.2  0.5 0.0   x       = 0.0  0.0          0.5    0.2  0.5 1.0              

i can numpy:

x_vals = np.array([[1.0, 0.0, 1.0],[0.0, 0.0, 1.0], [0.0, 1.0, 1.0], [1.0, 1.0, 1.0]]) deltas = np.array([0.2, 0.5])  def mult(x):     return x*deltas  #i can this... x in x_vals:     print mult(x.reshape(3,1)) 

i can't tensorflow?

x_vals = np.array([[1.0, 0.0, 1.0],[0.0, 0.0, 1.0], [0.0, 1.0, 1.0], [1.0, 1.0, 1.0]]) deltas = np.array([0.2, 0.5])  def mult(x):     return x*deltas x = tf.placeholder('float', (none,3)) delta = tf.constant(deltas) result = mult(tf.reshape(x, shape=(3,1))) init = tf.global_variables_initializer()  # create session , run graph tf.session() sess:     sess.run(init)     arr =  sess.run(result, feed_dict={x: x_vals}) 

it seems passes in entire x_val array, , not sure looping on session.run each entry how supposed work. can give me pointer?

in numpy can simplified :x_vals[:,:,np.newaxis]*deltas[np.newaxis,:]

this should work in tensorflow well:

x_vals = np.array([[1.0, 0.0, 1.0],[0.0, 0.0, 1.0], [0.0, 1.0, 1.0], [1.0, 1.0, 1.0]]) deltas = np.array([0.2, 0.5])  def mult(x):    return x[:,:,tf.newaxis]*deltas[tf.newaxis,:] x = tf.placeholder('float', (none,3)) delta = tf.constant(deltas) result = mult(x) init = tf.global_variables_initializer()  # create session , run graph tf.session() sess: sess.run(init) arr =  sess.run(result, feed_dict={x: x_vals}) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -