[Numpy-discussion] histogramdd shapes
Ben Granett
granett@IfA.Hawaii....
Sat Mar 17 19:46:35 CDT 2007
Hi,
There seems to be a problem with histogramdd (numpy 1.0.1). Depending on the
number of bins in each axis, it may not produce an array with the dimensions
oriented correctly. The bug is in the axis swapping code at the end of the
routine.
To reproduce, you can run,
>>> x = random.randn(100,3)
>>> H, edg = histogramdd(x, bins=(7,5,6))
>>> print H.shape
(5, 7, 6)
A fix is to replace this:
# Shape into a proper matrix
hist = hist.reshape(sort(nbin))
for i,j in enumerate(ni):
hist = hist.swapaxes(i,j)
if (hist.shape == nbin).all():
break
with this:
for i in arange(nbin.size):
j = ni[i]
hist = hist.swapaxes(i,j)
ni[i],ni[j] = ni[j],ni[i]
That is, elements of ni need to be swapped too.
I hope this wasn't a known bug, but I couldn't find any mention of it. Thanks,
Ben
More information about the Numpy-discussion
mailing list