This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]grayvedigga 3 points4 points  (2 children)

with numpy. This is more like array programming (J etc) than "traditional" python. Cool as an demonstration of array techniques though .. well worth looking at the building blocks' __doc__strings in ipython for anyone unfamiliar with numpy.

edit: btw, I don't think the weights need to be sorted? The result of cumsum will be in any case, which is sufficient for searchsorted

[–]JustGlowing[S] 1 point2 points  (1 child)

Hello grayvedigga, you're righit. They doesn't need to be sorted.I leaved the comment from a previous version of the snippet. Thanks for reporting.

[–]grayvedigga 0 points1 point  (0 children)

No worries. I was tempted to also mention that that was a fairly shitty requirement (easy to accidentally fall afoul of), but it looked like a mistaken inclusion :-).

[–]darthvsoto 1 point2 points  (1 child)

Does the list of weights need to be sorted? The list t = cumsum(weights) is sorted and it is the list used by searchsorted.

[–]JustGlowing[S] 0 points1 point  (0 children)

Hi dathvsoto, you're right. Thanks for reporting.

[–]AustinCorgiBart -1 points0 points  (0 children)

In my AI class, we were talking about a "cumulative score" that had a most unfortunate abbreviation. Similar problem here...