Tensorflow的broadcast_to无法正常工作,看到AttributeError:'module'对象没有属性'broadcast_to'

时间:2019-01-20 15:57:03

标签: python tensorflow attributeerror

取自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。为什么会这样/我该如何解决?感谢您提供任何见解!

1 个答案:

答案 0 :(得分:0)

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