gpt4 book ai didi

python-2.7 - Tensor对数组可变

转载 作者:行者123 更新时间:2023-12-04 01:55:15 26 4
gpt4 key购买 nike

我正在尝试评估theano TensorValue表达式:

import pymc3
import numpy as np
with pymc3.Model():
growth = pymc3.Normal('growth_%s' % 'some_name', 0, 10)

x = np.arange(4)
(x * growth).eval()


但是得到错误

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/graph.py", line 522, in eval
self._fn_cache[inputs] = theano.function(inputs, self)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function.py", line 317, in function
output_keys=output_keys)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/pfunc.py", line 486, in pfunc
output_keys=output_keys)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 1839, in orig_function
name=name)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 1487, in __init__
accept_inplace)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 181, in std_fgraph
update_mapping=update_mapping)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 175, in __init__
self.__import_r__(output, reason="init")
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 346, in __import_r__
self.__import__(variable.owner, reason=reason)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 391, in __import__
raise MissingInputError(error_msg, variable=r)
theano.gof.fg.MissingInputError: Input 0 of the graph (indices start from 0), used to compute InplaceDimShuffle{x}(growth_some_name), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.


我试过了
有人可以帮我看看theano变量实际输出什么吗?
谢谢!
我正在使用Python 2.7和theano 1.0.3

最佳答案

虽然PyMC3发行版是TensorVariable对象,但在抽样之外它们在技术上没有任何要评估的值。如果需要值,则必须至少在模型上运行采样:

with pymc3.Model():
growth = pymc3.Normal('growth', 0, 10)

trace = pymc3.sample(10)

x = np.arange(4)
x[:, np.newaxis]*trace['growth']


如果要在采样期间查看节点值,则需要使用 theano.tensor.printing.Print对象。有关更多信息,请参见 the PyMC3 debugging tips

关于python-2.7 - Tensor对数组可变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53308711/

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