我想用Python的Numpy来计算自动bin大小的直方图。我的documentation读说我应该能够通过bins="auto"
,但是当我这样做,我得到一个错误:“列表分配索引超出范围”与numpy.histogram
import sys
import numpy as np
print(sys.version)
# 2.7.10 (default, Oct 23 2015, 19:19:21)
# [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]
print(np.version.version)
# 1.8.0rc1
print(np.histogram([1, 2, 3, 4], bins='auto'))
# Traceback (most recent call last):
# File "/Users/phrogz/Code/histopy/histo.py", line 11, in <module>
# print(np.histogram([1, 2, 3, 4], bins='auto'))
# File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/function_base.py", line 183, in histogram
# if (np.diff(bins) < 0).any():
# File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/function_base.py", line 991, in diff
# slice1[axis] = slice(1, None)
# IndexError: list assignment index out of range#
#
# Process finished with exit code 1
我得到相同的结果与bins
任何字符串参数,而它按预期工作如果我提供参数的任何整数。我做错了什么,以及如何获得自动纸盒尺寸计算?
既然你得到了回溯,你可以调试。看起来像自动计算的“箱子”碰巧超出范围,但我不知道为什么。 –