Vimlan.G
Vimlan.G

Reputation: 193

store high decimal values in python Tensorflow

value1 and value 2 is an array, has values close to each other This would result temp to have very high decimal values

temp = tf.sub(value1,value2)

However, when I tried to print temp out, it contains array with 0.0 values due to high decimal values in the array.

How do I maintain the precision of all the variables?

Upvotes: 0

Views: 319

Answers (1)

Miriam Farber
Miriam Farber

Reputation: 19624

You can do that by setting the type of value1 and value2 before applying tf.sub. For example:

value1=tf.constant(5.0000000001,dtype=tf.float64)
value2=tf.constant(5.0000000002,dtype=tf.float64)
s=tf.sub(value1,value2)
sess=tf.InteractiveSession()
s.eval()

This prints -1.000000082740371e-10

Same for arrays:

value1=tf.constant([5.0000000001,2.0001],dtype=tf.float64)
value2=tf.constant([5.0000000002,2.000],dtype=tf.float64)
s=tf.sub(value1,value2)
sess=tf.InteractiveSession()
s.eval()

This prints array([ -1.00000008e-10, 1.00000000e-04])

Upvotes: 1

Related Questions