gpt4 book ai didi

python - 将python ndarray转换为theano张量类型变量

转载 作者:太空宇宙 更新时间:2023-11-03 14:57:40 25 4
gpt4 key购买 nike

我有像这样的 ndarray:

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 张量变量?因为我需要像这样执行点操作

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 - 将python ndarray转换为theano张量类型变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41198973/

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