0

I have a tensor:

numbers = tf.constant([[4.00, 3.33], [2.34, 7.00]])

What I want to do is get a tensor that has the same dimensions as 'numbers', but has 1's at the indices where numbers is a whole number, and 0's at the indices where it is not, like so:

ans = [[1, 0],[0, 1]]

I'm guessing I would have to use tf.where() maybe? I'm really unsure how to do something like this using tensorflow. Thank you

JavaNewb
  • 155
  • 1
  • 7

1 Answers1

0
import tensorflow as tf
import numpy as np

tf.reset_default_graph()
with tf.Session() as sess:
    fake_data = np.asarray([[1,2.4, 3.5], [3.4, 2.00, 10.001], [105.1, 100, 10]])
    a = tf.constant(data)

    # find where floor == actual value (thus, is a whole number)
    mask = tf.equal(tf.floor(data), data)

    # Get the indices
    idx = tf.where(mask)


    print(sess.run(a))
    print(sess.run(idx))

This should do the trick :) I tried commenting it so that what I was doing was clear and I think it's easy to understand. What I wrote is based on this comment

IanQ
  • 1,831
  • 5
  • 20
  • 29