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

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

摘自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)

当我 运行 这段代码时,我得到

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'

我正在使用 Python3.4 和 tensorflow 1.4.1。为什么这个 happening/how 我可以修复?感谢您的任何见解!

tf.broadcast_to 仅在比 1.4 更新的 tensorflow 版本中添加。尝试使用最新版本(撰写本文时为 1.12 post)。