[Numpy-discussion] LaTeX version of boolean indexing

Andras Deak deak.andris at gmail.com
Thu Oct 11 13:29:12 EDT 2018


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


More information about the NumPy-Discussion mailing list