擅长:python、mysql、java
<p>我不知道我是否误解了你的意思,但是<code>nmag.dot(nmag.T)</code>会得到你想要的吗</p>
<pre><code>In [5]: nmag.dot(nmag.T)
Out[5]:
array([[1. , 0.92794895, 0.60097537, 0.60509647, 0.6158193 ],
[0.92794895, 0.99999999, 0.81220999, 0.76275381, 0.85745291],
[0.60097537, 0.81220999, 1.00000001, 0.9753569 , 0.96833458],
[0.60509647, 0.76275381, 0.9753569 , 1. , 0.89150645],
[0.6158193 , 0.85745291, 0.96833458, 0.89150645, 1. ]])
</code></pre>
<p>如果你只想得到不同行的点积</p>
<pre><code>In [17]: res = nmag.dot(nmag.T)
In [18]: [res[i, j] for i in range(res.shape[0]) for j in range(res.shape[1]) if i<j]
Out[18]:
[0.9279489524047824,
0.6009753676942861,
0.6050964675806133,
0.6158193009466447,
0.8122099927113468,
0.7627538110746328,
0.8574529124107328,
0.9753568970221529,
0.9683345820770881,
0.8915064490330812]
</code></pre>