[Numpy-discussion] index partition

Alexander Belopolsky ndarray at mac.com
Sat Apr 12 17:20:59 EDT 2014


On Sat, Apr 12, 2014 at 5:03 PM, Sebastian Berg
<sebastian at sipsolutions.net>wrote:

> > As a simple example, suppose for array `a` I want
> > np.flatnonzero(a>0) and np.flatnonzero(a<=0).
> > Can I get them both in one go?
> >
>
> Might be missing something, but I don't think there is a way to do it in
> one go. The result is irregularly structured and there are few functions
> like nonzero which give something like that.


The "set routines" [1] are in this category and may help you deal with
partitions, but I would recommend using boolean arrays instead. If you
commonly deal with both a subset and a complement, set representation does
not give you a memory advantage over a boolean mask.

[1] http://docs.scipy.org/doc/numpy/reference/routines.set.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140412/151fc2da/attachment.html>


More information about the NumPy-Discussion mailing list