Repository: QuantEcon/QuantEcon.py

Issue:
ecdf function needs to be vectorized
The **call** method in ecdf.py needs to be vectorized so that it works as a ufunc (acts pointwise on arrays)


Discussion:

Patch:
diff --git a/quantecon/ecdf.py b/quantecon/ecdf.py
index e0c648e..a426046 100644
--- a/quantecon/ecdf.py
+++ b/quantecon/ecdf.py
@@ -48,4 +48,7 @@ class ECDF:
             Fraction of the sample less than x
 
         """
-        return np.mean(self.observations <= x)
+        def f(a):
+            return np.mean(self.observations <= a)
+        vf = np.frompyfunc(f, 1, 1)
+        return vf(x).astype(float)


Test patch:
diff --git a/quantecon/tests/test_ecdf.py b/quantecon/tests/test_ecdf.py
index 8081955..2c283da 100644
--- a/quantecon/tests/test_ecdf.py
+++ b/quantecon/tests/test_ecdf.py
@@ -30,3 +30,14 @@ class TestECDF(unittest.TestCase):
         F_1 = self.ecdf(x)
         F_2 = self.ecdf(1.1 * x)
         self.assertGreaterEqual(F_2, F_1)
+
+    def test_vectorized(self):
+        "ecdf: testing vectorized __call__ method"
+        t = np.linspace(-1, 1, 100)
+        e = self.ecdf(t)
+        self.assertEqual(t.shape, e.shape)
+        self.assertEqual(e.dtype, float)
+        t = np.linspace(-1, 1, 100).reshape(2, 2, 25)
+        e = self.ecdf(t)
+        self.assertEqual(t.shape, e.shape)
+        self.assertEqual(e.dtype, float)