for the sum function part,<div>It's not a good way to fix but... if you want more accuracy</div><div><div><br></div><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">x=(np.array([1]*10000 + </span><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">[1e4]</span><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">, dtype=np.float32))</span></div>


<div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">np.sum(x*x)</span><br><div>1.0001e+08</div>
<div><br></div><div>You can sort x from small numbers to bigger numbers before you call sum.</div><div><br></div><div>-Kibeom Kim</div><div><br></div><div class="gmail_quote">On Sat, Mar 5, 2011 at 6:27 PM, Xavier Gnata <span dir="ltr"><<a href="mailto:xavier.gnata@gmail.com" target="_blank">xavier.gnata@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I got this problem in a real life code and it took me some time to<br>
figure out that np.linalg.norm has a terrible numerical behavior.<br>
The problem is nicely described here<br>
<a href="http://fseoane.net/blog/2011/computing-the-vector-norm/" target="_blank">http://fseoane.net/blog/2011/computing-the-vector-norm/</a><br>
<br>
numpy/linalg/linalg.py claims to be a "high-level Python interface to<br>
the LAPACK library".<br>
That's great but the low level norm function is coded in pure python :<br>
     x = asarray(x)<br>
     if ord is None: # check the default case first and handle it<br>
immediately<br>
         return sqrt(add.reduce((x.conj() * x).ravel().real))<br>
<br>
Is there a way to use *by default* the blas function to compute the norm?<br>
<br>
ok....looks like sum as the same terrible numerical behavior<br>
x=(np.array([1e4] + [1]*10000, dtype=np.float32))<br>
np.sum(x*x)<br>
returns 1e+08 instead of 1.0001e+08<br>
<br>
Moreover, np.linalg.norm is slow compare to blas.<br>
<br>
Is there a way/plan to fix it?<br>
<br>
Xavier<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br></div></div>