<div dir="ltr"><div class="markdown-here-wrapper" style="font-size:1em;font-family:Helvetica,arial,freesans,clean,sans-serif;color:rgb(34,34,34);background-color:rgb(255,255,255);border:none;line-height:1.2"><p style="margin:1em 0px">David, that doesn’t work, because <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">np.cumsum(mask)[mask]</code> is always equal to <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">np.arange(mask.sum()) + 1</code>. Robert’s answer is correct.</p>
<p style="margin:1em 0px">Eric</p>
<p style="margin:1em 0px">On Sat, 21 Oct 2017 at 13:12 Daπid <<a href="mailto:davidmenhur@gmail.com" target="_blank" style="color:rgb(51,51,238);text-decoration:none">davidmenhur@gmail.com</a>> wrote:</p>
<p style="margin:1em 0px"></p><div class="markdown-here-exclude"><p></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 21 October 2017 at 21:03, Robert Kern <span dir="ltr"><<a href="mailto:robert.kern@gmail.com" target="_blank">robert.kern@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span class="m_-3393541316675321068m_-3515059439514252209gmail-"></span>Index with a boolean mask.<div><br></div><div>mask = (tmp_px > 2)</div><div>px = tmp_px[mask]</div><div>py = tmp_py[mask]</div><div># ... etc.<br><br></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>That isn't equivalent, note that j only increases when tmp_px > 2. I think you can do it with something like:</div><div><br></div><div>mask = tmp_px > 2</div><div> j_values = np.cumsum(mask)[mask]</div><div>i_values = np.arange(len(j_values))</div><div><br></div><div>px[i_values] = tmp_i[j_values]<br></div><div><br></div><br></div></div></div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote><p></p></div><p style="margin:1em 0px"></p>
<div title="MDH:RGF2aWQsIHRoYXQgZG9lc24ndCB3b3JrLCBiZWNhdXNlIGA8c3BhbiBzdHlsZT0iY29sb3I6IHJn
YigzMywgMzMsIDMzKTsgZm9udC1zaXplOiAxM3B4OyI+bnAuY3Vtc3VtKG1hc2spW21hc2tdYDwv
c3Bhbj7CoGlzIGFsd2F5cyBlcXVhbCB0byBgbnAuYXJhbmdlKG1hc2suc3VtKCkpICsgMWAuIFJv
YmVydCdzIGFuc3dlciBpcyBjb3JyZWN0LjxkaXY+PGJyPjwvZGl2PjxkaXY+RXJpYzxicj48YnI+
PGRpdiBjbGFzcz0iZ21haWxfcXVvdGUiPjxkaXYgZGlyPSJsdHIiPk9uIFNhdCwgMjEgT2N0IDIw
MTcgYXQgMTM6MTIgRGHPgGlkICZsdDs8YSBocmVmPSJtYWlsdG86ZGF2aWRtZW5odXJAZ21haWwu
Y29tIiB0YXJnZXQ9Il9ibGFuayI+ZGF2aWRtZW5odXJAZ21haWwuY29tPC9hPiZndDsgd3JvdGU6
PGJyPjwvZGl2PjxibG9ja3F1b3RlIGNsYXNzPSJnbWFpbF9xdW90ZSIgc3R5bGU9Im1hcmdpbjow
IDAgMCAuOGV4O2JvcmRlci1sZWZ0OjFweCAjY2NjIHNvbGlkO3BhZGRpbmctbGVmdDoxZXgiPjxk
aXYgZGlyPSJsdHIiPjxkaXYgY2xhc3M9ImdtYWlsX2V4dHJhIj48ZGl2IGNsYXNzPSJnbWFpbF9x
dW90ZS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90ZT48L2Rpdj48L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div>