[Numpy-discussion] histogramdd shapes

David Huard david.huard at gmail.com
Fri Mar 23 10:18:04 EDT 2007


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 <granett at ifa.hawaii.edu>:
>
> 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 at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070323/525b4379/attachment.html>


More information about the NumPy-Discussion mailing list