【问题标题】:module 'tensorflow' has no attribute 'variable' in google Colaboratory模块'tensorflow'在google Colaboratory中没有属性'variable'
【发布时间】:2021-08-19 09:20:03
【问题描述】:

我正在尝试使用此代码在 google Collaboratory 中创建变量张量,但由于 TensorFlow 没有关于变量的模块而出错。有什么解决办法?

import tensorflow as tf
var_1 = tf.variable(tf.ones([2,3]))

错误:

AttributeError                            Traceback (most recent call last)
    <ipython-input-2-2666f49bf801> in <module>()
    ----> 1 var_1 = tf.variable(tf.ones([2,3]))```
    
AttributeError: module 'tensorflow' has no attribute 'variable'

【问题讨论】:

标签: python tensorflow variables google-colaboratory


【解决方案1】:

有一个拼写错误。变量使用大写字母 V。

你可以参考下面的代码。

import tensorflow as tf

var_1 = tf.Variable(tf.ones([2,3]))

var_1

点击here,了解更多详情

【讨论】:

    猜你喜欢
    • 2019-04-13
    • 2020-10-17
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 2020-02-04
    • 2019-09-18
    • 2019-09-16
    相关资源
    最近更新 更多