[Numpy-discussion] add axis to results of reduction (mean, min, ...)

Keith Goodman kwgoodman at gmail.com
Thu Aug 6 13:07:13 EDT 2009


On Thu, Aug 6, 2009 at 9:58 AM, Charles R
Harris<charlesr.harris at gmail.com> wrote:
>
>
> On Thu, Aug 6, 2009 at 9:55 AM, <josef.pktd at gmail.com> wrote:
>>
>> What's the best way of getting back the correct shape to be able to
>> broadcast, mean, min,.. to the original array, that works for
>> arbitrary dimension and axis?
>>
>> I thought I have seen some helper functions, but I don't find them
>> anymore?
>
> Adding a keyword to retain the number of dimensions has been mooted. It
> shouldn't be too difficult to implement and would allow things like:
>
>>>> scaled = a/a.max(1, reduce=0)
>
> I could do that for 1.4 if folks are interested.

I'd use that. It's better than what I usually do:

scaled = a / a.max(1).reshape(-1,1)



More information about the NumPy-Discussion mailing list