《深度学习的数学——使用Python语言》第6章 线性代数进阶学习笔记
<p><span style="font-family:Times;"><span style="font-size:16px;">方阵学习</span></span></p><p ><span style="font-family:Times;"><span style="font-size:16px;">方阵在线性代数的世界里有特殊的地位。</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">转置</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">对军阵进行转置是指将矩阵中的行元素和列元素关于主对角线对调。</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">在numpy中,我们可以通过调用transpose函数对数组进行转置</span></span></p>
<pre>
<code class="language-python">a2 = np.array([, , ])
print(a2)
print(a2.transpose())
print("转置矩阵矩阵是:\n")
print(a2.T)</code></pre>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">执行结果</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">矩阵的迹</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">例程</span></span></p>
<pre>
<code class="language-python">b = np.array([, ])
print(np.diag(b))
print("矩阵的迹是:\n")
print(np.trace(b))</code></pre>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">结果</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p > </p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">矩阵的矩阵幂运算</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">调用matrix_power进行幂运算</span></span></p>
<pre>
<code class="language-python">yu = np.array([, ])
print("矩阵的幂是:\n")
print(matrix_power(yu, 2))</code></pre>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">结果</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p > </p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">特征向量和特征值</span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">我们可以通过np.linalg.eig函数得到矩阵的特征向量和特征值</span></span></p>
<pre>
<code class="language-python">yi = np.array([, [-2, -3]])
print("矩阵的特征值和特征向量是:\n")
print(np.linalg.eig(yi))
print(np.linalg.eig(yi))</code></pre>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">Np.linalg.eig函数将返回一个列表,其中的第一项是由矩阵的所有特征值构成的向量,第二项则是一个矩阵,其中的每一列元素是与各个特征值对应的特征向量。</span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p>线性代数还可以这样编程学习,厉害</p>
Jacktang 发表于 2025-1-18 09:52
线性代数还可以这样编程学习,厉害
<p>这个Python做线性代数太方便了 太高效了</p>
页:
[1]