fork(1) download
  1. import tensorflow as tf
  2. import numpy as np
  3. rule_tag = tf.constant([[7],[5],[5],[5],[7]])
  4. preds = tf.constant([[0.9],[1.5],[1.1]])
  5. print(rule_tag)
  6. eq = tf.equal(tf.constant(7, dtype=tf.int32), rule_tag)
  7. indices = tf.reduce_max(tf.where(eq, tf.ones_like(rule_tag), tf.zeros_like(rule_tag)), axis=1)
  8.  
  9. indices2 = tf.stack([tf.range(tf.shape(indices)[0]), tf.cast(indices, tf.int32)], axis=1)
  10. preds_add = tf.concat([preds, tf.zeros([tf.shape(preds)[0],1])], axis=1)
  11. sess = tf.Session()
  12. print(sess.run(preds_add))
  13.  
  14. # Learns best fit is W: [0.1], b: [0.3]# your code goes here
Success #stdin #stdout 1.23s 203748KB
stdin
Standard input is empty
stdout
Tensor("Const:0", shape=(5, 1), dtype=int32)
[[0.9 0. ]
 [1.5 0. ]
 [1.1 0. ]]