[Numpy-discussion] MATLAB to Numpy

Daπid davidmenhur at gmail.com
Sat Oct 21 16:11:38 EDT 2017


On 21 October 2017 at 21:03, Robert Kern <robert.kern at gmail.com> wrote:

> Index with a boolean mask.
>
> mask = (tmp_px > 2)
> px = tmp_px[mask]
> py = tmp_py[mask]
> # ... etc.
>
>
That isn't equivalent, note that j only increases when tmp_px > 2. I think
you can do it with something like:

mask = tmp_px > 2
j_values = np.cumsum(mask)[mask]
i_values = np.arange(len(j_values))

px[i_values] = tmp_i[j_values]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20171021/569c546f/attachment.html>


More information about the NumPy-Discussion mailing list