Skip to content

Instantly share code, notes, and snippets.

@fabianp
Created April 6, 2011 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabianp/905457 to your computer and use it in GitHub Desktop.
Save fabianp/905457 to your computer and use it in GitHub Desktop.
Print error distribution for norm
import pylab as pl
import numpy as np
import scipy.linalg
nrm2, = scipy.linalg.get_blas_funcs(('nrm2',), np.empty(0, dtype=np.float32))
x_min, x_max = -4., 0
y_min, y_max = 0, 4.
h = 134567e-7
xx, yy = np.meshgrid(np.arange(x_min, x_max, h, dtype=np.float32),
np.arange(y_min, y_max, h, dtype=np.float32))
points = np.c_[xx.ravel(), yy.ravel()]
norm_delta = np.empty(points.shape[0], dtype=np.float32)
for i, p in enumerate(points):
norm_delta[i] = np.abs(nrm2(p) - np.sqrt(np.dot(p, p)))
#norm_delta[i] = np.abs(nrm2(p) - scipy.linalg.norm(p))
Z = norm_delta.reshape(xx.shape)
pl.contourf(xx, yy, Z)
pl.colorbar()
pl.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment