Ejemplo n.º 1
0
 def test_polyfit(self):
     # Tests polyfit
     # On ndarrays
     x = np.random.rand(10)
     y = np.random.rand(20).reshape(-1, 2)
     assert_almost_equal(polyfit(x, y, 3), np.polyfit(x, y, 3))
     # ON 1D maskedarrays
     x = x.view(MaskedArray)
     x[0] = masked
     y = y.view(MaskedArray)
     y[0, 0] = y[-1, -1] = masked
     #
     (C, R, K, S, D) = polyfit(x, y[:, 0], 3, full=True)
     (c, r, k, s, d) = np.polyfit(x[1:],
                                  y[1:, 0].compressed(),
                                  3,
                                  full=True)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
     #
     (C, R, K, S, D) = polyfit(x, y[:, -1], 3, full=True)
     (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1, -1], 3, full=True)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
     #
     (C, R, K, S, D) = polyfit(x, y, 3, full=True)
     (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1, :], 3, full=True)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
     #
     w = np.random.rand(10) + 1
     wo = w.copy()
     xs = x[1:-1]
     ys = y[1:-1]
     ws = w[1:-1]
     (C, R, K, S, D) = polyfit(x, y, 3, full=True, w=w)
     (c, r, k, s, d) = np.polyfit(xs, ys, 3, full=True, w=ws)
     assert_equal(w, wo)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
Ejemplo n.º 2
0
 def test_polyfit(self):
     # Tests polyfit
     # On ndarrays
     x = np.random.rand(10)
     y = np.random.rand(20).reshape(-1, 2)
     assert_almost_equal(polyfit(x, y, 3), np.polyfit(x, y, 3))
     # ON 1D maskedarrays
     x = x.view(MaskedArray)
     x[0] = masked
     y = y.view(MaskedArray)
     y[0, 0] = y[-1, -1] = masked
     #
     (C, R, K, S, D) = polyfit(x, y[:, 0], 3, full=True)
     (c, r, k, s, d) = np.polyfit(x[1:], y[1:, 0].compressed(), 3,
                                  full=True)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
     #
     (C, R, K, S, D) = polyfit(x, y[:, -1], 3, full=True)
     (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1, -1], 3, full=True)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
     #
     (C, R, K, S, D) = polyfit(x, y, 3, full=True)
     (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1,:], 3, full=True)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
     #
     w = np.random.rand(10) + 1
     wo = w.copy()
     xs = x[1:-1]
     ys = y[1:-1]
     ws = w[1:-1]
     (C, R, K, S, D) = polyfit(x, y, 3, full=True, w=w)
     (c, r, k, s, d) = np.polyfit(xs, ys, 3, full=True, w=ws)
     assert_equal(w, wo)
     for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
         assert_almost_equal(a, a_)
Ejemplo n.º 3
0
    def test_polyfit_with_masked_NaNs(self):
        x = np.random.rand(10)
        y = np.random.rand(20).reshape(-1, 2)

        x[0] = np.nan
        y[-1, -1] = np.nan
        x = x.view(MaskedArray)
        y = y.view(MaskedArray)
        x[0] = masked
        y[-1, -1] = masked

        (C, R, K, S, D) = polyfit(x, y, 3, full=True)
        (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1, :], 3, full=True)
        for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
            assert_almost_equal(a, a_)
Ejemplo n.º 4
0
    def test_polyfit_with_masked_NaNs(self):
        x = np.random.rand(10)
        y = np.random.rand(20).reshape(-1, 2)

        x[0] = np.nan
        y[-1,-1] = np.nan
        x = x.view(MaskedArray)
        y = y.view(MaskedArray)
        x[0] = masked
        y[-1,-1] = masked

        (C, R, K, S, D) = polyfit(x, y, 3, full=True)
        (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1,:], 3, full=True)
        for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
            assert_almost_equal(a, a_)