gpt4 book ai didi

python - Tensorflow session - session 上下文的范围?

转载 作者:行者123 更新时间:2023-12-01 01:43:54 25 4
gpt4 key购买 nike

import tensorflow as tf

...

with tf.Session() as sess:
output = sess.run(result)
print(output)

print(output)

为什么最后一行有效? output 是否超出了范围,因为它是在生成器内声明的?

最佳答案

在 python with 中没有类似作用域的方法,这篇文章解释得更清楚 Variable defined with with-statement available outside of with-block?

为您节省一些时间

the context manager will be available outside the with statement and that is not implementation or version dependent. with statements do not create a new execution scope.

关于python - Tensorflow session - session 上下文的范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51601167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com