##// END OF EJS Templates
Merge pull request #2179 from dopplershift/pylab-switch...
Merge pull request #2179 from dopplershift/pylab-switch Enable switching %pylab mode between inline and a single gui mode in a single notebook. With this merge, `%pylab` can be called interactively to toggle inline/GUI (matplotlib floating windows) mode. After initializing `%pylab inline`, now one can call `%pylab` without arguments to activate the default GUI or ask for a specific one as usual. IPython will detect if a different GUI is requested if one was already activated and will refuse to do so (to prevent multiple event loops from running concurrently, which often leads to problems).

File last commit:

r4910:0dc49390
r8027:6dac6929 merge
Show More
phistogram.py
40 lines | 1.2 KiB | text/x-python | PythonLexer
MinRK
updates to docs and examples
r3670 """Parallel histogram function"""
import numpy
MinRK
update a few parallel examples...
r4184 from IPython.parallel import Reference
MinRK
updates to docs and examples
r3670
MinRK
remove kernel examples already ported to newparallel
r3675 def phistogram(view, a, bins=10, rng=None, normed=False):
MinRK
updates to docs and examples
r3670 """Compute the histogram of a remote array a.
MinRK
remove kernel examples already ported to newparallel
r3675 Parameters
----------
view
IPython DirectView instance
MinRK
updates to docs and examples
r3670 a : str
String name of the remote array
bins : int
Number of histogram bins
rng : (float, float)
Tuple of min, max of the range to histogram
normed : boolean
Should the histogram counts be normalized to 1
"""
MinRK
remove kernel examples already ported to newparallel
r3675 nengines = len(view.targets)
# view.push(dict(bins=bins, rng=rng))
with view.sync_imports():
import numpy
rets = view.apply_sync(lambda a, b, rng: numpy.histogram(a,b,rng), Reference(a), bins, rng)
hists = [ r[0] for r in rets ]
lower_edges = [ r[1] for r in rets ]
# view.execute('hist, lower_edges = numpy.histogram(%s, bins, rng)' % a)
lower_edges = view.pull('lower_edges', targets=0)
hist_array = numpy.array(hists).reshape(nengines, -1)
# hist_array.shape = (nengines,-1)
MinRK
updates to docs and examples
r3670 total_hist = numpy.sum(hist_array, 0)
if normed:
total_hist = total_hist/numpy.sum(total_hist,dtype=float)
return total_hist, lower_edges