将 python ndarray 转换为 theano 张量类型变量 [英] convert python ndarray to theano tensor type variable

查看:59
本文介绍了将 python ndarray 转换为 theano 张量类型变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像这样的 ndarray :

I have ndarray like :

diag = []
diag.append(np.diag([1,1,0]))
diag.append(np.diag([0,1,1]))
diag
  [array([[1, 0, 0],
   [0, 1, 0],
   [0, 0, 0]]), array([[0, 0, 0],
   [0, 1, 0],
   [0, 0, 1]])]

如何将其转换为 float 64, matrix 类型的 Theano 张量变量?因为我需要执行像

How can I convert it into Theano tensor variable of type float 64, matrix ? As I need to perform dot operation like

Theano.dot(diag, X) where X is shared variable of type float 64, matrix.

推荐答案

只需像这样创建一个SharedVariable

diag_ = theano.shared(np.array(diag).astype("float64"))
theano.dot(diag_, X)

http://deeplearning.net/software/theano/library/compile/shared.html

这篇关于将 python ndarray 转换为 theano 张量类型变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆