pan> <span class="o">**</span> <span class="mi">2</span>
                <span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">((</span><span class="n">v</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
            <span class="n">itercount</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># using Tr(X.T Y) = Sum[ij](Xij * Yij)</s