[Numpy-discussion] np.histogramdd of empty data

Ralf Gommers ralf.gommers@googlemail....
Wed Mar 23 15:16:38 CDT 2011


On Tue, Mar 22, 2011 at 11:28 AM, Nils Becker <n.becker@amolf.nl> wrote:
> Hi,
>
> I was wondering why histogram2d and histogramdd raise a ValueError when
> fed with empty data of the correct dimensions. I came across this as a
> corner case when calling histogram2d from my own specialized histogram
> function.

Many function in numpy don't work with empty inputs, no big surprise.
>
> In comparison, histogram does handle this case correctly when bins are
> specified explicitely (obviously automatic binning cannot work without
> data...)

That seems to be more an accident then anything else, empty input is
not checked for or handled in histogram.

This fixes it I think (please check, I just used your examples as test
cases): https://github.com/rgommers/numpy/tree/histogram-empty

Cheers,
Ralf


> np.histogram([], bins=([0,1]))
> (array([0]), array([0, 1]))
>
> np.histogram2d([],[], bins=([0,1],[0,1]))
> ValueError: zero-size array to ufunc.reduce without identity
>
> np.histogramdd([[],[]], bins=([0,1],[0,1]))
> ValueError: zero-size array to ufunc.reduce without identity
>
> cheers, nils
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list