On 12/09/2007, Robert Kern <[EMAIL PROTECTED]> wrote:
> That sentence applies to the 3-argument form, which has nothing to do with
> nonzero() and does not yield a tuple. But in general, yes, the docstring
> leaves
> much to be desired.
Well, here's what I hope is a step in the right direction.
Anne
Index: numpy/add_newdocs.py
===================================================================
--- numpy/add_newdocs.py (revision 4028)
+++ numpy/add_newdocs.py (working copy)
@@ -339,19 +339,28 @@
""")
add_newdoc('numpy.core.multiarray','where',
- """where(condition, | x, y)
+ """where(condition) or where(condition, x, y)
- The result is shaped like condition and has elements of x and y where
- condition is respectively true or false. If x or y are not given,
- condition.nonzero() is returned.
+ For the three-argument form, the result is shaped like condition and
+ has elements of x and y where condition is respectively true or false.
+ For example, to take the absolute value of a:
+ where(a>=0, a, -a)
+
+
+ If x and y are not given, condition.nonzero() is returned. This has
+ the effect of returning a tuple suitable for fancy indexing.
To group the indices by element, rather than dimension, use
transpose(where(condition))
instead. This always results in a 2d array, with a row of indices for
- each element that satisfies the condition.
+ each element that satisfies the condition, so that
+ transpose(where(a<0))[i]
+
+ is a vector you can use to select the ith negative entry of a.
+
""")
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion