[Numpy-discussion] Pull Request Review: R-like sample function

Christopher Jordan-Squire cjordan1@uw....
Fri Sep 2 12:17:18 CDT 2011


On Thu, Sep 1, 2011 at 10:55 PM, Nathaniel Smith <njs@pobox.com> wrote:
> On Thu, Sep 1, 2011 at 8:31 PM, Christopher Jordan-Squire
> <cjordan1@uw.edu> wrote:
>> On Thu, Sep 1, 2011 at 11:14 PM, Robert Kern <robert.kern@gmail.com> wrote:
>>> On Thu, Sep 1, 2011 at 22:07, Christopher Jordan-Squire <cjordan1@uw.edu> wrote:
>>>
>>>> So in the mean time, are there any suggestions for what this R sample
>>>> function should be called, since random.sample is apparently taken?
>>>
>>> If you default to size=1 (which you probably should anyways), then
>>> np.random.choice() makes sense, in analogy to random.choice() from the
>>> standard library.
>>>
>> Alright. I can make that change tomorrow. I'd prefer np.sample in the
>> long-run, for compatibility with R. (False friends are loathsome
>> things.)  How does one petition to get function names deprecated?
>
> I was about to argue that "random.choice" was a better name anyway,
> but then I remembered that the standard library "random.sample" exists
> and does something similar. So instead I'd like to argue that making
> this compatible with Python is more important than making it
> compatible with R :-).
>
> Specifically, 'np.random.sample(array_like, k)', with no further
> arguments, should perform random sampling *without* replacement.
> Ideally it should also efficiently handle the case where array_like is
> an xrange object. Docs are here:
> http://docs.python.org/library/random.html
>

I mentioned this at the end of my initial response to Josef. I agree
that my use of sample is more consistent with the python random
library's usage, except that I don't want to have the same name but a
different default. I think that also counts as a 'false friend'. So I
think np.random.choice is a better name for right now. Simpler to have
the same function with the same defaults but a different name than the
same function with the same name and different defaults.

-Chris


> -- Nathaniel
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list