Some numpy functions (logically) return scalars:
>>> my_arr = np.ndarray(shape=(1,))
>>> type(np.max(my_arr))
<type 'numpy.float64'>
but only when called with an ndarray, rather than a subclass:
>>> class CustomArray(np.ndarray):
... pass
>>> my_arr = CustomArray(shape=(1,))
>>> type(np.max(my_arr))
<class '__main__.CustomArray'>
Why is this? I'd expect either both to return a scalar (of type <type 'numpy.float64'>, or the former to return a np.ndarray instance and the latter a CustomArray instance. But instead, I get a combination of these two behaviours. Can I change this behaviour through changing my own class?
I don't see anything that would explain this on the doc page discussing subclassing ndarray (http://docs.scipy.org/doc/numpy-1.9.2/user/basics.subclassing.html).
(Running Python 2.7.10, numpy 1.9.2, in case it matters.)