diff options
author | pierregm <pierregm@localhost> | 2008-08-07 14:50:52 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2008-08-07 14:50:52 +0000 |
commit | 0bdef198361c01a820c69f34580b2da3e3eebbfb (patch) | |
tree | de6b5b77ab75220f4885166f4066b8906b98ddc4 | |
parent | 469c4d3d5417f5693ad8e326d7069cdec7c92663 (diff) | |
download | numpy-0bdef198361c01a820c69f34580b2da3e3eebbfb.tar.gz |
* core : minor doc formatting
* test_extras: switched to assert_almost_equal in TestCov and TestCorrcoef
-rw-r--r-- | numpy/ma/core.py | 110 | ||||
-rw-r--r-- | numpy/ma/tests/test_extras.py | 50 |
2 files changed, 81 insertions, 79 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 1811788b9..ec7d8de57 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2384,7 +2384,7 @@ masked_%(name)s(data = %(data)s, Parameters ---------- - axis : {None, -1, int}, optional + axis : {None, int}, optional Axis over which the product is taken. If None is used, then the product is over all the array elements. dtype : {None, dtype}, optional @@ -2422,10 +2422,10 @@ masked_%(name)s(data = %(data)s, Notes ----- - Arithmetic is modular when using integer types, and no error is - raised on overflow. + Arithmetic is modular when using integer types, and no error is raised + on overflow. - """ + """ _mask = ndarray.__getattribute__(self, '_mask') newmask = _mask.all(axis=axis) # No explicit output @@ -2835,53 +2835,52 @@ masked_%(name)s(data = %(data)s, def sort(self, axis=-1, kind='quicksort', order=None, endwith=True, fill_value=None): - """Sort along the given axis. - - Parameters - ---------- - axis : int - Axis to be indirectly sorted. - kind : {string} - Sorting algorithm (default 'quicksort') - Possible values: 'quicksort', 'mergesort', or 'heapsort'. - order : {var} - If a has fields defined, then the order keyword can be - the field name to sort on or a list (or tuple) of - field names to indicate the order that fields should - be used to define the sort. - fill_value : {var} - Value used to fill in the masked values. If None, use - the the output of minimum_fill_value(). - endwith : bool - Whether missing values (if any) should be forced in - the upper indices (at the end of the array) (True) or - lower indices (at the beginning). + """ + Sort along the given axis. - Returns - ------- - When used as method, returns None. - When used as a function, returns an array. + Parameters + ---------- + axis : {int}, optional + Axis to be indirectly sorted. + kind : {'quicksort', 'mergesort', or 'heapsort'}, optional + Sorting algorithm (default 'quicksort') + Possible values: 'quicksort', 'mergesort', or 'heapsort'. + order : {None, var} + If a has fields defined, then the order keyword can be the field name + to sort on or a list (or tuple) of field names to indicate the order + that fields should be used to define the sort. + endwith : {True, False}, optional + Whether missing values (if any) should be forced in the upper indices + (at the end of the array) (True) or lower indices (at the beginning). + fill_value : {var} + Value used to fill in the masked values. If None, use + the the output of minimum_fill_value(). - Notes - ----- - This method sorts 'a' in place along the given axis using - the algorithm specified by the kind keyword. - - The various sorts may characterized by average speed, - worst case performance need for work space, and whether - they are stable. A stable sort keeps items with the same - key in the same relative order and is most useful when - used w/ argsort where the key might differ from the items - being sorted. The three available algorithms have the - following properties: + Returns + ------- + - When used as method, returns None. + - When used as a function, returns an array. - |------------------------------------------------------| - | kind | speed | worst case | work space | stable| - |------------------------------------------------------| - |'quicksort'| 1 | O(n^2) | 0 | no | - |'mergesort'| 2 | O(n*log(n)) | ~n/2 | yes | - |'heapsort' | 3 | O(n*log(n)) | 0 | no | - |------------------------------------------------------| + Notes + ----- + This method sorts 'a' in place along the given axis using + the algorithm specified by the kind keyword. + + The various sorts may characterized by average speed, + worst case performance need for work space, and whether + they are stable. A stable sort keeps items with the same + key in the same relative order and is most useful when + used w/ argsort where the key might differ from the items + being sorted. The three available algorithms have the + following properties: + + |------------------------------------------------------| + | kind | speed | worst case | work space | stable| + |------------------------------------------------------| + |'quicksort'| 1 | O(n^2) | 0 | no | + |'mergesort'| 2 | O(n*log(n)) | ~n/2 | yes | + |'heapsort' | 3 | O(n*log(n)) | 0 | no | + |------------------------------------------------------| """ if self._mask is nomask: @@ -3024,7 +3023,7 @@ masked_%(name)s(data = %(data)s, axis : {None, int}, optional Axis along which to find the peaks. If None (default) the flattened array is used. - out : array_like + out : {None, array_like}, optional Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. @@ -3060,13 +3059,14 @@ masked_%(name)s(data = %(data)s, squeeze = _arraymethod('squeeze') #-------------------------------------------- def tolist(self, fill_value=None): - """Copy the data portion of the array to a hierarchical python - list and returns that list. + """ + Copy the data portion of the array to a hierarchical python + list and returns that list. - Data items are converted to the nearest compatible Python - type. Masked values are converted to fill_value. If - fill_value is None, the corresponding entries in the output - list will be ``None``. + Data items are converted to the nearest compatible Python + type. Masked values are converted to fill_value. If + fill_value is None, the corresponding entries in the output + list will be ``None``. """ if fill_value is not None: diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index ff061d8dd..9fd501aaa 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -363,18 +363,18 @@ class TestCov(TestCase): def test_1d_wo_missing(self): "Test cov on 1D variable w/o missing values" x = self.data - assert_equal(np.cov(x), cov(x)) - assert_equal(np.cov(x, rowvar=False), cov(x, rowvar=False)) - assert_equal(np.cov(x, rowvar=False, bias=True), - cov(x, rowvar=False, bias=True)) + assert_almost_equal(np.cov(x), cov(x)) + assert_almost_equal(np.cov(x, rowvar=False), cov(x, rowvar=False)) + assert_almost_equal(np.cov(x, rowvar=False, bias=True), + cov(x, rowvar=False, bias=True)) # def test_2d_wo_missing(self): "Test cov on 1 2D variable w/o missing values" x = self.data.reshape(3,4) - assert_equal(np.cov(x), cov(x)) - assert_equal(np.cov(x, rowvar=False), cov(x, rowvar=False)) - assert_equal(np.cov(x, rowvar=False, bias=True), - cov(x, rowvar=False, bias=True)) + assert_almost_equal(np.cov(x), cov(x)) + assert_almost_equal(np.cov(x, rowvar=False), cov(x, rowvar=False)) + assert_almost_equal(np.cov(x, rowvar=False, bias=True), + cov(x, rowvar=False, bias=True)) # def test_1d_w_missing(self): "Test cov 1 1D variable w/missing values" @@ -395,10 +395,10 @@ class TestCov(TestCase): # 2 1D variables w/ missing values nx = x[1:-1] assert_almost_equal(np.cov(nx, nx[::-1]), cov(x, x[::-1])) - assert_equal(np.cov(nx, nx[::-1], rowvar=False), - cov(x, x[::-1], rowvar=False)) - assert_equal(np.cov(nx, nx[::-1], rowvar=False, bias=True), - cov(x, x[::-1], rowvar=False, bias=True)) + assert_almost_equal(np.cov(nx, nx[::-1], rowvar=False), + cov(x, x[::-1], rowvar=False)) + assert_almost_equal(np.cov(nx, nx[::-1], rowvar=False, bias=True), + cov(x, x[::-1], rowvar=False, bias=True)) # def test_2d_w_missing(self): "Test cov on 2D variable w/ missing value" @@ -427,18 +427,20 @@ class TestCorrcoef(TestCase): def test_1d_wo_missing(self): "Test cov on 1D variable w/o missing values" x = self.data - assert_equal(np.corrcoef(x), corrcoef(x)) - assert_equal(np.corrcoef(x, rowvar=False), corrcoef(x, rowvar=False)) - assert_equal(np.corrcoef(x, rowvar=False, bias=True), - corrcoef(x, rowvar=False, bias=True)) + assert_almost_equal(np.corrcoef(x), corrcoef(x)) + assert_almost_equal(np.corrcoef(x, rowvar=False), + corrcoef(x, rowvar=False)) + assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True), + corrcoef(x, rowvar=False, bias=True)) # def test_2d_wo_missing(self): "Test corrcoef on 1 2D variable w/o missing values" x = self.data.reshape(3,4) - assert_equal(np.corrcoef(x), corrcoef(x)) - assert_equal(np.corrcoef(x, rowvar=False), corrcoef(x, rowvar=False)) - assert_equal(np.corrcoef(x, rowvar=False, bias=True), - corrcoef(x, rowvar=False, bias=True)) + assert_almost_equal(np.corrcoef(x), corrcoef(x)) + assert_almost_equal(np.corrcoef(x, rowvar=False), + corrcoef(x, rowvar=False)) + assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True), + corrcoef(x, rowvar=False, bias=True)) # def test_1d_w_missing(self): "Test corrcoef 1 1D variable w/missing values" @@ -459,10 +461,10 @@ class TestCorrcoef(TestCase): # 2 1D variables w/ missing values nx = x[1:-1] assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1])) - assert_equal(np.corrcoef(nx, nx[::-1], rowvar=False), - corrcoef(x, x[::-1], rowvar=False)) - assert_equal(np.corrcoef(nx, nx[::-1], rowvar=False, bias=True), - corrcoef(x, x[::-1], rowvar=False, bias=True)) + assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False), + corrcoef(x, x[::-1], rowvar=False)) + assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False, bias=True), + corrcoef(x, x[::-1], rowvar=False, bias=True)) # def test_2d_w_missing(self): "Test corrcoef on 2D variable w/ missing value" |