python - 如何用python生成身份张量?

标签 python numpy tensorflow identity tensor

我知道 np.eye生成单位矩阵。我的意思是单位矩阵为

In linear algebra, the identity matrix, or sometimes ambiguously called a unit matrix, of size n is the n × 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/

相关文章:

algorithm - 在 numpy 的条件函数之前是否有一个保持值?

tensorflow - 如何使用FFT和神经网络对声音进行分类?我应该使用 CNN 还是 RNN?

python - tensorflow 中的三阶张量与二阶张量相乘

python - 413 Request Entity too Large - 如何使用python拆分多个文件

python - 具有强制数据类型和维度的输入 numpy 数组的文档字符串格式

python - 如何创建 numpy 数组的不规则间隔切片的 View ?

tensorflow - 在 TensorFlow 中,是否可以对网络的不同部分使用不同的学习率?

python - GAE 在哪里存储永久链接?

Python,多线程,抓取网页,下载网页

python - 尝试将 CSV 转换为数据帧时出现 IOError