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

Robert Kern robert.kern@gmail....
Thu Aug 6 11:26:51 CDT 2009

On Thu, Aug 6, 2009 at 11:21, <josef.pktd@gmail.com> wrote:
> On Thu, Aug 6, 2009 at 12:07 PM, Robert Kern<robert.kern@gmail.com> wrote:

>> if axis != 0:
>>    ind = [slice(None)] * x.ndim
>>    ind[axis] = np.newaxis
> Thanks, that's it.
> I have seen implementation of helper functions similar to this in
> other packages, but I thought there is already something in numpy.  I
> think this should be a simple helper function in numpy to avoid
> mistakes and complicated implementation like the one in stats.nanstd
> even if it's only a few lines.

It would make a good contribution to numpy.lib.index_tricks.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list