Plotting histograms
Robert Kern
robert.kern at gmail.com
Wed Oct 18 02:25:30 EDT 2006
amitsoni.1984 at gmail.com wrote:
> Thanks Robert,
>
> My previous problem is solved(I was using 'from matplotlib.pylab import
> *') but now I am facing another problem. I want to plot the histogram
> of eigenvalues calculated and I am using the following code:
> _______________________________________________________________________
> import numpy
> from matplotlib import pylab
>
> n=100
> ra = numpy.random
> la = numpy.linalg
>
> A = ra.standard_normal((n,n))
> S = (A + numpy.transpose(A))/(2*n^(1/2))
Note that this line won't do what you think it does. First, one integer divided
by another integer returns an integer, so (1/2) == 0. Also, ^ is not
exponentiation but bitwise XOR. Use ** for exponentiation. However, in this
case, you should use numpy.sqrt().
> eig = la.eigvals(S)
>
> [N,x]=pylab.hist(eig, 10) # make a histogram
> -------------------------------------------------------------------------------------------------------------
>
> But again it is giving some error, which is given below:
>
> File "C:\Documents and Settings\amitsoni\Desktop\New
> Folder\wignerpython", line 15, in <module>
> [N,x]=pylab.hist(eig, 10) # make a histogram
> ValueError: too many values to unpack
>
> Can anyone help me out with this??
pylab.hist() does not return two values, it returns three. Sorry I didn't catch
that earlier.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list