[Numpy-discussion] Thoughts for 1.1
Travis E. Oliphant
oliphant at enthought.com
Wed Apr 2 18:40:13 EDT 2008
Charles R Harris wrote:
> Hi All,
>
> I think it would enhance broadcasting if functions like sum, mean, etc
> didn't change the number of dimensions. For example, suppose one
> wanted to subtract the mean along dimension 2 from the same axis of
> the original array, then something like
>
> In [44]: a = ones((2,3,4,5))
>
> In [45]: a -= a.mean(2)
>
> would do the trick. Similar modifications might also suit functions of
> the argmax, argmin, argsort type and allow a common argtake function
> that would allow one to take along a specified axis, making easy
> something that is somewhat complicated at the moment.
I generally like the idea because I've seen this pattern many times
myself and been annoyed at having to "add back" a dimension to make it
work right.
>
> The main drawback that I see is that scalars would no longer be 0D,
> but that could be special cased as scalars will broadcast correctly no
> matter the ndim.
Robert's point about code-breakage is relevant, however. I'd like to
see some discussion on how gratuitous this actually is. What kind of
code will actually break? Sure, the shape will be different, but will
that matter greatly?
Basically a.mean(2).squeeze() would restore current behavior.
Alternatively, a.mean(axis=2, keepshape=1) could also be used, right?
The advantage is that this could be added now.
-Travis
> Chuck
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list