hist doesn't like 2d arrays

Dear Folks,

I'm finding that hist has problems computing on 2d arrays.

    import numpy
    import pylab
    mu, sigma = 2, 0.5
    v = numpy.random.normal(mu,sigma,160000)
    pylab.hist(v, bins=1000, normed=1)

This works without any problems. But if you try this:

    pylab.hist(w, bins=1000, normed=1)

it doesn't come back on my machine until all of memory is used up. However:

    n,bins = numpy.histogram(w,bins=1000,normed=1)

works just fine.

That's by design. For a n x m array, pylab.hist is doing m times a histogram of the n items subarray and then tries to plot them somehow on top of each other. The detail I don't know, but most likely you want to do
pylab.hist(w.flatten(), ....)
to get a 1-dim array that you want to fill in ONE histogram. (for example for image arrays).



On 2011-02-18 07:32:48 +0100, Robert Abiad said:

The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.