@@ -0,0 +1,958 @@
+import numpy as np%0Aimport collections%0Aimport types%0A%0Adef histogram(rdd, range=None, bins=10):%0A  %22%22%22%0A  Compute the histogram of an RDD.%0A  %22%22%22%0A  def _bin(num, bin_edges):%0A    %22%22%22%0A    Given a number and set of bins defined by edges, computes which bin the number%0A    lies in.  Lower edges are inclusive, higher are exclusive.%0A    %22%22%22%0A    if num %3C bin_edges%5B0%5D:%0A      return %5B%5D%0A%0A    for i, edge in enumerate(bin_edges%5B1:%5D):%0A      if num %3C edge:%0A        return %5Bi%5D%0A%0A    return %5B%5D%0A%0A  if isinstance(bins, collections.Iterable):%0A    bin_edges = bins%0A  elif type(bins) is types.IntType:%0A    if range is None:%0A      raise TypeError(%22range argument required when bins is an int%22)%0A    bin_edges = np.linspace(range%5B0%5D, range%5B1%5D, bins+1)%0A  else:%0A    raise TypeError(%22bins required to be an int or iterable%22)%0A%0A  return (rdd.flatMap(lambda x: _bin(x, bin_edges)).countByValue(), bin_edges)%0A%0A~                                                                                 %0A

Add histogram