Tag Archives: ‘tensorflow‘ has no attribute ‘sub‘

‘tensorflow‘ has no attribute ‘sub‘ [How to Solve]

When learning tensorflow, I did it according to the official example and found one

Traceback (most recent call last):
  File "interactive.py", line 10, in <module>
    sub = tf.sub(x,a)
AttributeError: module 'tensorflow' has no attribute 'sub'

As soon as I guess, I guess the name of the function has changed. Sure enough, it has been replaced by substract

# -*- coding: utf-8 -*-
import tensorflow as tf
sess = tf.InteractiveSession()

x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0])

x.initializer.run()

sub = tf.subtract(x,a)
print(sub.eval())