<p>我知道<code>np.eye</code>,它生成单位矩阵。我是说单位矩阵是</p>
<blockquote>
<p>In linear algebra, the identity matrix, or sometimes ambiguously called a <code>unit matrix</code>, of size n is the <code>n × n</code> square matrix with ones on the main diagonal and zeros elsewhere.</p>
</blockquote>
<p>我知道我们可以在<code>Numpy</code>中用<code>np.identity(3)</code>创建它。在</p>
<blockquote>
<p>But, I would like to know how can I have an identity Tensor in python. </p>
</blockquote>
<p>我想在张量乘法中使用单位张量。如下所示:</p>
<p>其中<code>G = Er ×1 U1 ×2 U2 ...×M</code><code>UM</code>是变换张量,<code>Er ∈</code>
<code>R</code><code>r×r×...×r</code>是一个恒等张量(对角线元素是1,所有其他条目都是0)。我需要生成<code>identity tensor</code>的代码。在</p>
<p>提前谢谢你。在</p>