<div dir="ltr"><a href="https://github.com/numpy/numpy/issues/8708">https://github.com/numpy/numpy/issues/8708</a> is a proposal to add such a function, with an implementation in <a href="https://github.com/numpy/numpy/pull/8714">https://github.com/numpy/numpy/pull/8714</a> <br><div><br></div><div>Eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 26 Mar 2018 at 11:35 Benjamin Root <<a href="mailto:ben.v.root@gmail.com">ben.v.root@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Ah, yes, I should have thought about that. Kind of seems like something that we could make `np.take()` do, somehow, for something that is easier to read.<br><br></div>Thank you!<br></div>Ben Root<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 26, 2018 at 2:28 PM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span>On Mon, Mar 26, 2018 at 11:24 AM, Benjamin Root <<a href="mailto:ben.v.root@gmail.com" target="_blank">ben.v.root@gmail.com</a>> wrote:<br>><br>> I seem to be losing my mind... I can't seem to get this to work right.<br>><br>> I have a (N, k) array `distances` (along with a bunch of other arrays of the same shape). I need to resort the rows, so I do:<br>><br>> indexs = np.argsort(distances, axis=1)<br>><br>> How do I use this index array correctly to get back distances sorted along rows? Note, telling me to use `np.sort()` isn't going to work because I need to apply the same indexing to a couple of other arrays.<br>><br>> new_dists = distances[indexs]<br>><br>> gives me a (N, k, k) array, while<br>><br>> new_dists = np.take(indexs, axis=1)<br>><br>> gives me a (N, N, k) array.<br>><br>> What am I missing?<br><br></span>Broadcasting!<div><br></div><div>  new_dists = distances[np.arange(N)[:, np.newaxis], indexs]<br><br>--<br>Robert Kern</div></div>
<br>_______________________________________________<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>
<br></blockquote></div><br></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></div>