module 'tensorflow' has no attribute 'random_normal'
时间: 2023-08-04 20:06:34 浏览: 44
这个错误是因为在TensorFlow2.0及以上版本中,random_normal方法已经被替换为random.normal方法。所以在你的代码中,需要将tf.random_normal改为tf.random.normal来解决这个问题。例如,将W的定义改为:W = tf.Variable(tf.random.normal(\[1\]), name="weight")。\[1\]
另外,你提供的第二个引用显示了一个报错信息,指出模块'tensorflow'没有random_normal属性。这也是因为在TensorFlow2.0及以上版本中,random_normal方法已经被替换为random.normal方法。所以你需要将tf.random_normal改为tf.random.normal来解决这个问题。\[2\]
最后,你提供的第三个引用显示了正确的代码,其中使用了tf.random_normal方法。但是请注意,这个引用只是为了展示正确的代码,并不是解决你的问题的方法。你需要将tf.random_normal改为tf.random.normal来解决报错问题。\[3\]
#### 引用[.reference_title]
- *1* [Python报错-AttributeError: module ‘tensorflow‘ has no attribute ‘random_normal‘的解决方法](https://blog.csdn.net/zkw_1998/article/details/120829362)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [AttributeError: module 'tensorflow' has no attribute 'random_normal'](https://blog.csdn.net/studyvcmfc/article/details/105319997)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]