summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2007-05-28 12:55:25 +0000
committerStefan van der Walt <stefan@sun.ac.za>2007-05-28 12:55:25 +0000
commita27258edf4103aa0d3d1bce13c1acb987cbe7dca (patch)
treef8da280399392a8cc7524ed6d863ceb8943fee5c /numpy/lib
parent944c32ad4a0618c834dcb06e50e90267df1d6835 (diff)
downloadnumpy-a27258edf4103aa0d3d1bce13c1acb987cbe7dca.tar.gz
Clean up select docstring.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py46
-rw-r--r--numpy/lib/tests/test_function_base.py8
2 files changed, 29 insertions, 25 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 5d0d7c1a6..4c0d671de 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -418,32 +418,30 @@ def piecewise(x, condlist, funclist, *args, **kw):
return y
def select(condlist, choicelist, default=0):
- """ Return an array composed of different elements of choicelist
+ """Return an array composed of different elements in choicelist,
depending on the list of conditions.
- condlist is a list of condition arrays containing ones or zeros
-
- choicelist is a list of choice arrays (of the "same" size as the
- arrays in condlist). The result array has the "same" size as the
- arrays in choicelist. If condlist is [c0, ..., cN-1] then choicelist
- must be of length N. The elements of the choicelist can then be
- represented as [v0, ..., vN-1]. The default choice if none of the
- conditions are met is given as the default argument.
-
- The conditions are tested in order and the first one statisfied is
- used to select the choice. In other words, the elements of the
- output array are found from the following tree (notice the order of
- the conditions matters):
-
- if c0: v0
- elif c1: v1
- elif c2: v2
- ...
- elif cN-1: vN-1
- else: default
-
- Note that one of the condition arrays must be large enough to handle
- the largest array in the choice list.
+ :Parameters:
+ condlist : list of N boolean arrays of length M
+ The conditions C_0 through C_(N-1) which determine
+ from which vector the output elements are taken.
+ choicelist : list of N arrays of length M
+ Th vectors V_0 through V_(N-1), from which the output
+ elements are chosen.
+
+ :Returns:
+ output : 1-dimensional array of length M
+ The output at position m is the m-th element of the first
+ vector V_n for which C_n[m] is non-zero. Note that the
+ output depends on the order of conditions, since the
+ first satisfied condition is used.
+
+ Equivalent to:
+
+ output = []
+ for m in range(M):
+ output += [V[m] for V,C in zip(values,cond) if C[m]]
+ or [default]
"""
n = len(condlist)
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index b22ce1318..77cc29199 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -65,6 +65,12 @@ class test_average(NumpyTestCase):
assert_array_equal(actual, desired)
class test_select(NumpyTestCase):
+ def _select(self,cond,values,default=0):
+ output = []
+ for m in range(len(cond)):
+ output += [V[m] for V,C in zip(values,cond) if C[m]] or [default]
+ return output
+
def check_basic(self):
choices = [array([1,2,3]),
array([4,5,6]),
@@ -73,7 +79,7 @@ class test_select(NumpyTestCase):
array([0,1,0]),
array([0,0,1])]
assert_array_equal(select(conditions,choices,default=15),
- [15,5,9])
+ self._select(conditions,choices,default=15))
assert_equal(len(choices),3)
assert_equal(len(conditions),3)