您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – 由于Theano和NumPy变量类型而出错

5b51 2022/1/14 8:22:10 python 字数 1968 阅读 541 来源 www.jb51.cc/python

我正在使用numpy 1.9和最新版本的Theano编写此代码,但是我收到了一个我无法解决的错误.我怀疑它可能是我声明变量类型的方式,但我无法解决它.我感谢你的建议.我想用矢量生成矩阵,并用偏差求和. import theano.tensor as T from theano import function import numpy as np import pprint def test_the

概述

import theano.tensor as T
from theano import function
import numpy as np
import pprint
def test_theano_matrix():
   pp = pprint.PrettyPrinter(indent=3)
   W= T.fmatrix()
   x=T.fvector()
   b= T.fvector()
   y = T.dot(W,x) + b
   lin_func = function([W,x,b],y)
   dt = np.dtype(np.float)
   w_inp = np.matrix('1 0;0 1',dtype=dt)
   x_inp = np.matrix('2;1',dtype=dt)
   b_inp = np.matrix('0;0',dtype=dt)
   lin_func(w_inp,x_inp,b_inp)

 if __name__ == '__main__':
   test_theano_matrix()

我收到以下错误

raise TypeError(err_msg,data)
TypeError: ('Bad input argument to theano function at index 0(0-based)','TensorType(float32,matrix) cannot store a value of dtype float64 without risking loss of precision. If you do not mind this loss,you can: 1) explicitly cast your data to float32,or 2) set "allow_input_downcast=True" when calling "function".',matrix([[ 1.,0.],[ 0.,1.]]))

谢谢你的时间!

[global]

floatX = float32

这似乎解决了一切.但是,您的问题显示略有不同的错误.但我认为这值得尝试.

总结

以上是编程之家为你收集整理的python – 由于Theano和NumPy变量类型而出错全部内容,希望文章能够帮你解决python – 由于Theano和NumPy变量类型而出错所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶