Inverse Distance Weighted (IDW) Interpolation with Python

changed 20 Oct: this class Invdisttree combines inverse-distance weighting and scipy.spatial.KDTree. Forget the original brute-force answer; this is imho the method of choice for scattered-data interpolation. “”” invdisttree.py: inverse-distance-weighted interpolation using KDTree fast, solid, local “”” from __future__ import division import numpy as np from scipy.spatial import cKDTree as KDTree # http://docs.scipy.org/doc/scipy/reference/spatial.html __date__ = “2010-11-09 … Read more

Meaning of inter_op_parallelism_threads and intra_op_parallelism_threads

The inter_op_parallelism_threads and intra_op_parallelism_threads options are documented in the source of the tf.ConfigProto protocol buffer. These options configure two thread pools used by TensorFlow to parallelize execution, as the comments describe: // The execution of an individual op (for some op types) can be // parallelized on a pool of intra_op_parallelism_threads. // 0 means the … Read more

How to “properly” print a list?

In Python 2: mylist = [‘x’, 3, ‘b’] print ‘[%s]’ % ‘, ‘.join(map(str, mylist)) In Python 3 (where print is a builtin function and not a syntax feature anymore): mylist = [‘x’, 3, ‘b’] print(‘[%s]’ % ‘, ‘.join(map(str, mylist))) Both return: [x, 3, b] This is using the map() function to call str for each … Read more

A very simple multithreading parallel URL fetching (without queue)

Simplifying your original version as far as possible: import threading import urllib2 import time start = time.time() urls = [“http://www.google.com”, “http://www.apple.com”, “http://www.microsoft.com”, “http://www.amazon.com”, “http://www.facebook.com”] def fetch_url(url): urlHandler = urllib2.urlopen(url) html = urlHandler.read() print “‘%s\’ fetched in %ss” % (url, (time.time() – start)) threads = [threading.Thread(target=fetch_url, args=(url,)) for url in urls] for thread in threads: thread.start() … Read more

How to make scipy.interpolate give an extrapolated result beyond the input range?

As of SciPy version 0.17.0, there is a new option for scipy.interpolate.interp1d that allows extrapolation. Simply set fill_value=”extrapolate” in the call. Modifying your code in this way gives: import numpy as np from scipy import interpolate x = np.arange(0,10) y = np.exp(-x/3.0) f = interpolate.interp1d(x, y, fill_value=”extrapolate”) print f(9) print f(11) and the output is: … Read more