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
Thanks Ben,
I submitted a patch with your fix.
Ticket 189 http://projects.scipy.org/scipy/numpy/ticket/189
David
2007/3/17, Ben Granett
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
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Ben Granett
-
David Huard