[Numpy-discussion] Shouldn't all in-place operations simply return self?
Wed Jan 16 19:53:58 CST 2013
On Wed, Jan 16, 2013 at 7:11 PM, eat <email@example.com> wrote:
> In a recent thread
> http://article.gmane.org/gmane.comp.python.numeric.general/52772 it was
> proposed that .fill(.) should return self as an alternative for a trivial
> I'm raising now the question: what if all in-place operations indeed could
> return self? How bad this would be? A 'strong' counter argument may be found
> at http://mail.python.org/pipermail/python-dev/2003-October/038855.html.
> But anyway, at least for me. it would be much more straightforward to
> implement simple mini dsl's
> (http://en.wikipedia.org/wiki/Domain-specific_language) a much more
> straightforward manner.
> What do you think?
I'm against it.
I think it requires too much thinking by users and developers.
The function in numpy are conceptually much closer to basic python,
not some heavy object oriented framework where we need lots of
(I thought I remembered some discussion and justification for
returning self in sqlalchemy for this, but couldn't find it.)
I'm chasing quite a few bugs with inplace operations
>>> a = np.arange(10)
>>> a *= np.pi
>>> a = np.random.random_integers(0, 5, size=5)
>>> b = a.sort()
array([0, 1, 2, 5, 5])
>>> b = np.random.shuffle(a)
>>> b = np.random.permutation(a)
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?
> P.S. FWIW, if this idea really gains momentum obviously I'm volunteering to
> create a PR of it.
> NumPy-Discussion mailing list
More information about the NumPy-Discussion