我想用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
任何字符串參數,而它按預期工作如果我提供參數的任何整數。我做錯了什麼,以及如何獲得自動紙盒尺寸計算?
既然你得到了回溯,你可以調試。看起來像自動計算的「箱子」碰巧超出範圍,但我不知道爲什麼。 –