def test_2d_waxis(self):
     # Tests median w/ 2D arrays and different axis.
     x = masked_array(np.arange(30).reshape(10, 3))
     x[:3] = x[-3:] = masked
     assert_equal(median(x), 14.5)
     assert_equal(median(x, axis=0), [13.5, 14.5, 15.5])
     assert_equal(median(x, axis=1), [0, 0, 0, 10, 13, 16, 19, 0, 0, 0])
     assert_equal(median(x, axis=1).mask, [1, 1, 1, 0, 0, 0, 0, 1, 1, 1])
Exemple #2
0
 def test_2d_waxis(self):
     # Tests median w/ 2D arrays and different axis.
     x = masked_array(np.arange(30).reshape(10, 3))
     x[:3] = x[-3:] = masked
     assert_equal(median(x), 14.5)
     assert_equal(median(x, axis=0), [13.5, 14.5, 15.5])
     assert_equal(median(x, axis=1), [0, 0, 0, 10, 13, 16, 19, 0, 0, 0])
     assert_equal(median(x, axis=1).mask, [1, 1, 1, 0, 0, 0, 0, 1, 1, 1])
 def test_3d(self):
     # Tests median w/ 3D
     x = np.ma.arange(24).reshape(3, 4, 2)
     x[x % 3 == 0] = masked
     assert_equal(median(x, 0), [[12, 9], [6, 15], [12, 9], [18, 15]])
     x.shape = (4, 3, 2)
     assert_equal(median(x, 0), [[99, 10], [11, 99], [13, 14]])
     x = np.ma.arange(24).reshape(4, 3, 2)
     x[x % 5 == 0] = masked
     assert_equal(median(x, 0), [[12, 10], [8, 9], [16, 17]])
Exemple #4
0
 def test_3d(self):
     # Tests median w/ 3D
     x = np.ma.arange(24).reshape(3, 4, 2)
     x[x % 3 == 0] = masked
     assert_equal(median(x, 0), [[12, 9], [6, 15], [12, 9], [18, 15]])
     x.shape = (4, 3, 2)
     assert_equal(median(x, 0), [[99, 10], [11, 99], [13, 14]])
     x = np.ma.arange(24).reshape(4, 3, 2)
     x[x % 5 == 0] = masked
     assert_equal(median(x, 0), [[12, 10], [8, 9], [16, 17]])
 def test_2d(self):
     # Tests median w/ 2D
     (n, p) = (101, 30)
     x = masked_array(np.linspace(-1., 1., n), )
     x[:10] = x[-10:] = masked
     z = masked_array(np.empty((n, p), dtype=float))
     z[:, 0] = x[:]
     idx = np.arange(len(x))
     for i in range(1, p):
         np.random.shuffle(idx)
         z[:, i] = x[idx]
     assert_equal(median(z[:, 0]), 0)
     assert_equal(median(z), 0)
     assert_equal(median(z, axis=0), np.zeros(p))
     assert_equal(median(z.T, axis=1), np.zeros(p))
Exemple #6
0
 def test_2d(self):
     # Tests median w/ 2D
     (n, p) = (101, 30)
     x = masked_array(np.linspace(-1., 1., n),)
     x[:10] = x[-10:] = masked
     z = masked_array(np.empty((n, p), dtype=float))
     z[:, 0] = x[:]
     idx = np.arange(len(x))
     for i in range(1, p):
         np.random.shuffle(idx)
         z[:, i] = x[idx]
     assert_equal(median(z[:, 0]), 0)
     assert_equal(median(z), 0)
     assert_equal(median(z, axis=0), np.zeros(p))
     assert_equal(median(z.T, axis=1), np.zeros(p))
 def test_out(self):
     x = masked_array(np.arange(30).reshape(10, 3))
     x[:3] = x[-3:] = masked
     out = masked_array(np.ones(10))
     r = median(x, axis=1, out=out)
     assert_equal(r, out)
     assert_(type(r) == MaskedArray)
Exemple #8
0
 def test_out(self):
     x = masked_array(np.arange(30).reshape(10, 3))
     x[:3] = x[-3:] = masked
     out = masked_array(np.ones(10))
     r = median(x, axis=1, out=out)
     assert_equal(r, out)
     assert_(type(r) == MaskedArray)
 def test_neg_axis(self):
     x = masked_array(np.arange(30).reshape(10, 3))
     x[:3] = x[-3:] = masked
     assert_equal(median(x, axis=-1), median(x, axis=1))
Exemple #10
0
 def test_neg_axis(self):
     x = masked_array(np.arange(30).reshape(10, 3))
     x[:3] = x[-3:] = masked
     assert_equal(median(x, axis=-1), median(x, axis=1))
Exemple #11
0
 def get_sigma_median_heuristic(X):
     dists=squareform(pdist(X, 'euclidean'))
     median_dist=median(dists[dists>0])
     sigma=sqrt(0.5*median_dist)
     return sigma