[Numpy-discussion] Shouldn't all in-place operations simply return self?

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Jan 17 10:24:29 EST 2013


On Thu, Jan 17, 2013 at 9:49 AM, Benjamin Root <ben.root at ou.edu> wrote:
>
>
> On Thu, Jan 17, 2013 at 8:54 AM, Jim Vickroy <jim.vickroy at noaa.gov> wrote:
>>
>> On 1/16/2013 11:41 PM, Nathaniel Smith wrote:
>>
>> On 16 Jan 2013 17:54, <josef.pktd at gmail.com> wrote:
>> > >>> a = np.random.random_integers(0, 5, size=5)
>> > >>> b = a.sort()
>> > >>> b
>> > >>> a
>> > array([0, 1, 2, 5, 5])
>> >
>> > >>> b = np.random.shuffle(a)
>> > >>> b
>> > >>> b = np.random.permutation(a)
>> > >>> b
>> > array([0, 5, 5, 2, 1])
>> >
>> > How do I remember if shuffle shuffles or permutes ?
>> >
>> > Do we have a list of functions that are inplace?
>>
>> I rather like the convention used elsewhere in Python of naming in-place
>> operations with present tense imperative verbs, and out-of-place operations
>> with past participles. So you have sort/sorted, reverse/reversed, etc.
>>
>> Here this would suggest we name these two operations as either shuffle()
>> and shuffled(), or permute() and permuted().
>>
>>
>> I like this (tense) suggestion.  It seems easy to remember.  --jv
>>
>>
>
> And another score for functions as verbs!

I don't thing the filled we discuss here is an action.

The current ``fill`` is an inplace operation, operating on an existing array.
``filled`` would be the analog that returns a copy.

However ``filled`` here is creating an object

I still think ``array_filled`` is the most precise

'''Create an array and initialize it with the ``value``, returning the array '''


my 2.5c

Josef

>
> :-P
>
> Ben Root
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list