[Numpy-discussion] LaTeX version of boolean indexing

Matthew Harrigan harrigan.matthew at gmail.com
Thu Oct 11 13:43:40 EDT 2018


My apologies, never write code directly in an email...
s/b:
mask = np.array([1, 0, 1], dtype=bool)

What do you mean by indicator?

On Thu, Oct 11, 2018 at 1:31 PM Andras Deak <deak.andris at gmail.com> wrote:

> On Thu, Oct 11, 2018 at 6:54 PM Matthew Harrigan
> <harrigan.matthew at gmail.com> wrote:
> >
> > Hello,
> >
> > I am documenting some code, translating the core of the algorithm to
> LaTeX.  The style I have currently is very similar to the einsum syntax
> (which is awesome btw).  Here is an example of some of the basic operations
> in NumPy.  One part I do not know how to capture well is boolean indexing,
> ie:
> >
> > mask = np.array([1, 0, 1])
> > x = np.array([1, 2, 3])
> > y = x[mask]
>
> That is fancy indexing with an index array rather than boolean
> indexing. That's why the result is [2, 1, 2] rather than [1, 3].
> In case this is really what you need, it's the case of your indices
> originating from another sequence: `y_i = x_{m_i}` where `m_i` is your
> indexing sequence.
> For proper boolean indexing you lose the one-to-one correspondence
> between input and output (due to the size almost always changing), so
> you might not be able to formalize it this nicely with an index
> appearing in both sides. But something with an indicator might work...
>
> András
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20181011/c16dbd76/attachment.html>


More information about the NumPy-Discussion mailing list