Re: [Numpy-discussion] np.histogramdd of empty data

2011-04-01 Thread Ralf Gommers
On Thu, Mar 31, 2011 at 8:00 PM, Benjamin Root ben.r...@ou.edu wrote:


 On Thu, Mar 31, 2011 at 12:32 PM, Ralf Gommers ralf.gomm...@googlemail.com
 wrote:

 -- Forwarded message --
 From: Ralf Gommers ralf.gomm...@googlemail.com
 Date: Thu, Mar 31, 2011 at 7:31 PM
 Subject: Re: [Numpy-discussion] np.histogramdd of empty data
 To: Nils Becker n.bec...@amolf.nl


 On Thu, Mar 31, 2011 at 12:33 PM, Nils Becker n.bec...@amolf.nl wrote:
  Hi Ralf,
 
  I cloned numpy/master and played around a little.
 
  when giving the bins explicitely, now histogram2d and histogramdd work
  as expected in all tests i tried.
 
 
  However, some of the cases with missing bin specification appear
  somewhat inconsistent.
 
  The first question is if creating arbitrary bins for empty data and
  empty bin specification is better than raising an Exception:
 
  Specifically:

 Bins of size 0 should give a meaningful error, I was just fixing that
 as part of #1788 in
 https://github.com/rgommers/numpy/tree/ticket-1788-histogramdd

  numpy.histogram2d([],[],bins=[0,0])
  (array([ 0.,  0.]), array([ 0.]), array([ 0.]))

 Now gives:
    ValueError: Element at index 0 in `bins` should be a positive integer.

  numpy.histogram([],bins=0)
  ValueError: zero-size array to minimum.reduce without identity

 Now gives:
    ValueError: `bins` should be a positive integer.


  so 1-d and 2-d behave not quite the same.
 
  also, these work (although with arbitrary bin edges):
 
  numpy.histogram2d([],[],bins=[1,1])
  (array([ 0.,  0.]), array([ 0.,  1.]), array([ 0.,  1.]))
 
  numpy.histogram2d([],[],bins=[0,1])
  (array([ 0.,  0.]), array([ 0.]), array([ 0.,  1.]))
 
  while this raises an error:
 
  numpy.histogram([],bins=1)
  ValueError: zero-size array to minimum.reduce without identity

 Now gives:
    (array([0]), array([ 0.,  1.]))


 Just for consistency's sake, maybe the same should be done for np.bincount()
 and np.digitize() for empty data (but known bins)?  I don't know if your fix
 to histogram does this or not, but the latest pull from numpy master doesn't
 do this.

It doesn't. There was a ticket for that already, #1387. I added the
desired behavior there. Since those functions are written in C it's a
little more time-consuming to fix.

Ralf
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.histogramdd of empty data

2011-03-31 Thread Nils Becker
Hi Ralf,

I cloned numpy/master and played around a little.

when giving the bins explicitely, now histogram2d and histogramdd work
as expected in all tests i tried.


However, some of the cases with missing bin specification appear
somewhat inconsistent.

The first question is if creating arbitrary bins for empty data and
empty bin specification is better than raising an Exception:

Specifically:

numpy.histogram2d([],[],bins=[0,0])
 (array([ 0.,  0.]), array([ 0.]), array([ 0.]))

numpy.histogram([],bins=0)
 ValueError: zero-size array to minimum.reduce without identity

so 1-d and 2-d behave not quite the same.

also, these work (although with arbitrary bin edges):

numpy.histogram2d([],[],bins=[1,1])
 (array([ 0.,  0.]), array([ 0.,  1.]), array([ 0.,  1.]))

numpy.histogram2d([],[],bins=[0,1])
 (array([ 0.,  0.]), array([ 0.]), array([ 0.,  1.]))

while this raises an error:

numpy.histogram([],bins=1)
 ValueError: zero-size array to minimum.reduce without identity

another thing with non-empty data:

numpy.histogram([1],bins=1)
 (array([1]), array([ 0.5,  1.5]))

numpy.histogram([1],bins=0)
 (array([], dtype=int64), array([ 0.5]))

while

numpy.histogram2d([1],[1],bins=A)
 ValueError: zero-size array to minimum.reduce without identity

(here A==[0,0] or A==[0,1] but not A==[1,1] which gives a result)

Nils
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.histogramdd of empty data

2011-03-31 Thread Ralf Gommers
-- Forwarded message --
From: Ralf Gommers ralf.gomm...@googlemail.com
Date: Thu, Mar 31, 2011 at 7:31 PM
Subject: Re: [Numpy-discussion] np.histogramdd of empty data
To: Nils Becker n.bec...@amolf.nl


On Thu, Mar 31, 2011 at 12:33 PM, Nils Becker n.bec...@amolf.nl wrote:
 Hi Ralf,

 I cloned numpy/master and played around a little.

 when giving the bins explicitely, now histogram2d and histogramdd work
 as expected in all tests i tried.


 However, some of the cases with missing bin specification appear
 somewhat inconsistent.

 The first question is if creating arbitrary bins for empty data and
 empty bin specification is better than raising an Exception:

 Specifically:

Bins of size 0 should give a meaningful error, I was just fixing that
as part of #1788 in
https://github.com/rgommers/numpy/tree/ticket-1788-histogramdd

 numpy.histogram2d([],[],bins=[0,0])
 (array([ 0.,  0.]), array([ 0.]), array([ 0.]))

Now gives:
   ValueError: Element at index 0 in `bins` should be a positive integer.

 numpy.histogram([],bins=0)
 ValueError: zero-size array to minimum.reduce without identity

Now gives:
   ValueError: `bins` should be a positive integer.


 so 1-d and 2-d behave not quite the same.

 also, these work (although with arbitrary bin edges):

 numpy.histogram2d([],[],bins=[1,1])
 (array([ 0.,  0.]), array([ 0.,  1.]), array([ 0.,  1.]))

 numpy.histogram2d([],[],bins=[0,1])
 (array([ 0.,  0.]), array([ 0.]), array([ 0.,  1.]))

 while this raises an error:

 numpy.histogram([],bins=1)
 ValueError: zero-size array to minimum.reduce without identity

Now gives:
   (array([0]), array([ 0.,  1.]))


 another thing with non-empty data:

 numpy.histogram([1],bins=1)
 (array([1]), array([ 0.5,  1.5]))

That is the correct answer.

 numpy.histogram([1],bins=0)
 (array([], dtype=int64), array([ 0.5]))

Now gives:
   ValueError: `bins` should be a positive integer.


 while

 numpy.histogram2d([1],[1],bins=A)
 ValueError: zero-size array to minimum.reduce without identity

 (here A==[0,0] or A==[0,1] but not A==[1,1] which gives a result)

Same sensible errors now, telling you bins elements shouldn't be 0.

Cheers,
Ralf
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.histogramdd of empty data

2011-03-31 Thread Benjamin Root
On Thu, Mar 31, 2011 at 12:32 PM, Ralf Gommers
ralf.gomm...@googlemail.comwrote:

 -- Forwarded message --
 From: Ralf Gommers ralf.gomm...@googlemail.com
 Date: Thu, Mar 31, 2011 at 7:31 PM
 Subject: Re: [Numpy-discussion] np.histogramdd of empty data
 To: Nils Becker n.bec...@amolf.nl


 On Thu, Mar 31, 2011 at 12:33 PM, Nils Becker n.bec...@amolf.nl wrote:
  Hi Ralf,
 
  I cloned numpy/master and played around a little.
 
  when giving the bins explicitely, now histogram2d and histogramdd work
  as expected in all tests i tried.
 
 
  However, some of the cases with missing bin specification appear
  somewhat inconsistent.
 
  The first question is if creating arbitrary bins for empty data and
  empty bin specification is better than raising an Exception:
 
  Specifically:

 Bins of size 0 should give a meaningful error, I was just fixing that
 as part of #1788 in
 https://github.com/rgommers/numpy/tree/ticket-1788-histogramdd

  numpy.histogram2d([],[],bins=[0,0])
  (array([ 0.,  0.]), array([ 0.]), array([ 0.]))

 Now gives:
ValueError: Element at index 0 in `bins` should be a positive integer.

  numpy.histogram([],bins=0)
  ValueError: zero-size array to minimum.reduce without identity

 Now gives:
ValueError: `bins` should be a positive integer.


  so 1-d and 2-d behave not quite the same.
 
  also, these work (although with arbitrary bin edges):
 
  numpy.histogram2d([],[],bins=[1,1])
  (array([ 0.,  0.]), array([ 0.,  1.]), array([ 0.,  1.]))
 
  numpy.histogram2d([],[],bins=[0,1])
  (array([ 0.,  0.]), array([ 0.]), array([ 0.,  1.]))
 
  while this raises an error:
 
  numpy.histogram([],bins=1)
  ValueError: zero-size array to minimum.reduce without identity

 Now gives:
(array([0]), array([ 0.,  1.]))


Just for consistency's sake, maybe the same should be done for np.bincount()
and np.digitize() for empty data (but known bins)?  I don't know if your fix
to histogram does this or not, but the latest pull from numpy master doesn't
do this.

Thanks,
Ben Root
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] np.histogramdd of empty data

2011-03-23 Thread Ralf Gommers
On Tue, Mar 22, 2011 at 11:28 AM, Nils Becker n.bec...@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

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion