如何在Python中生成两个矩阵的可用张量积 [英] How to generate a usable tensor product of two matrices in Python
本文介绍了如何在Python中生成两个矩阵的可用张量积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此线程成功回答了如何使用numpy计算两个张量的乘积Python中的矩阵.但是,我希望输出采用适当的矩阵格式,以便可以在不手动编辑的情况下对其进行进一步的计算.
This thread successfully answers how to use numpy to calculate the tensor product of two matrices in Python. However, I want the output to be in a proper matrix format so that further calculations can be performed on it without my manually editing it.
例如
I=matrix([[1,0],[0,1]])
print np.tensordot(I, I, axes=0)
给出输出:
[[[[1 0]
[0 1]]
[[0 0]
[0 0]]]
[[[0 0]
[0 0]]
[[1 0]
[0 1]]]]
我想要它的形式:
[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
以便我可以在程序本身中对其进行进一步的操作.
so that I can perform further operations on it within the program itself.
我该怎么做?
推荐答案
可以使用 查看全文