numpy.histogram2d - TypeError: len() of unsized object

315 views
Skip to first unread message

v_...@ukr.net

unread,
Jul 21, 2012, 12:08:48 PM7/21/12
to sage-s...@googlegroups.com
Hello!
I encountered the following problem today. A simple example code

import numpy
x = numpy.random.randn(3000)
y = numpy.random.randn(3000)
hist,xedges,yedges = numpy.histogram2d(x,y,bins=40)

which I took here:
http://www.physics.ucdavis.edu/~dwittman/Matplotlib-examples/
refused to work with this error message:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_6.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8
-*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode
("aW1wb3J0IG51bXB5Cgp4ID0gbnVtcHkucmFuZG9tLnJhbmRuKDMwMDApCnkgPSBudW1weS5yYW5kb20ucmFuZG4oMzAwMCkKCmhpc3QseGVkZ2VzLHllZGdlcyA9IG51bXB5Lmhpc3RvZ3JhbTJkKHgseSxiaW5zPTQwKQ=="),globals
())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1,
in <module> File "/tmp/tmpc6TrHD/___code___.py", line 8, in <module>
exec compile(u'hist,xedges,yedges = numpy.histogram2d
(x,y,bins=_sage_const_40 ) File "", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/numpy/lib/twodim_base.py",
line 615, in histogram2d hist, edges = histogramdd([x,y], bins, range,
normed, weights) File
"/usr/lib64/python2.7/site-packages/numpy/lib/function_base.py", line
298, in histogramdd nbin[i] = len(edges[i])+1 # +1 for outlier bins
TypeError: len() of unsized object


I found some Numpy tickets mentioning the same error message, but I'm
not sure whether they are relevant or not.
http://projects.scipy.org/numpy/ticket/2116
http://projects.scipy.org/numpy/ticket/1535

Currently I use Sage-5.1 and numpy-1.5.1.

Regards,
Vladimir

-----
<v_...@ukr.net>
Reply all
Reply to author
Forward
0 new messages