[Numpy-discussion] Rationale for returning type-wrapped min() / max() scalars? (was: Problem with ufunc of a numpy.ndarray derived class)

Hans Meine meine at informatik.uni-hamburg.de
Sun Jul 31 02:38:41 EDT 2011


On Fri, Jul 29, 2011 at 4:12 AM, Hans Meine <meine at informatik.uni-hamburg.de> wrote:
> 
> /home/hmeine/new_numpy/lib64/python2.6/site-packages/vigra/arraytypes.pyc in
> reshape(self, shape, order)
>    587
>    588     def reshape(self, shape, order='C'):
> --> 589         res = numpy.ndarray.reshape(self, shape, order)
>    590         res.axistags = AxisTags(res.ndim)
>    591         return res
> 
> TypeError: an integer is required
> 
> The problem is that 'self' has become a zero-rank array, and those cannot be
> reshaped in order to add singleton dimensions anymore.  IOW, if you implement
> sth. like broadcasting, this is made much harder.

Am 29.07.2011 um 15:28 schrieb Charles R Harris
> 
> What is self and shape in this example?

self is my zero-rank array, shape is (1,1) (just 'int's, I checked), and order is 'F'.

The problem is that reshape of a zero-rank-array fails with the above TypeError.

> Out of curiosity, if you don't support all the ndarray operations, why are you subclassing ndarray?

Oh, we *do* support all ndarray operations, at least we try to, but we did not pay attention to support instances with an empty shape tuple.  (And before 1.6.0, this did not bite us.)

In fact, we also found a not-too-complex workaround, very similar to the numpy.matrix one, but we still believe the new min() behavior to be strange and probably unwanted.

Have a nice day,
  Hans


More information about the NumPy-Discussion mailing list