Search code examples
pythontensorflowattributeerror

Tensorflow's broadcast_to not working, seeing AttributeError: 'module' object has no attribute 'broadcast_to'


Taken from https://www.tensorflow.org/api_docs/python/tf/broadcast_to:

import tensorflow as tf

with tf.Session() as sess:
    x = tf.constant([1, 2, 3])
    y = tf.broadcast_to(x, [3, 3]).eval()
    print(y)

When I run this code, I get

Traceback (most recent call last):
  File "tf_play.py", line 5, in <module>
    y = tf.broadcast_to(x, [3, 3]).eval()
AttributeError: 'module' object has no attribute 'broadcast_to'

I am using Python3.4 and tensorflow 1.4.1. Why is this happening/how can I fix? Thanks for any insights!


Solution

  • tf.broadcast_to was only added on a more recent version of tensorflow than 1.4. Try using the latest (1.12 as of the writing of this post).