我知道 np.eye
生成单位矩阵。我的意思是单位矩阵为
In linear algebra, the identity matrix, or sometimes ambiguously called a
unit matrix
, of size n is then × n
square matrix with ones on the main diagonal and zeros elsewhere.
我知道我们可以在
Numpy
中创建它与 np.identity(3)
.But, I would like to know how can I have an identity Tensor in python.
我想在张量乘法中使用恒等张量。像下面这样:
哪里
G = Er ×1 U1 ×2 U2 ...×M
UM
是一个变换张量,而 Er ∈
R
r×r×...×r
是一个单位张量(对角线元素为 1,所有其他条目为 0)。我需要有生成 identity tensor
的代码.先感谢您。
最佳答案
而不是 np.identity
使用 tf.eye
:
tf.eye(2)
# [[1., 0.],
# [0., 1.]]
关于python - 如何用python生成身份张量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54513204/