由于某种原因,Numpy 的 hist 总是返回比 MATLAB 的 hist 少 1 个 bin:
例如在 MATLAB 中:
x = [1,2,2,2,1,4,4,2,3,3,3,3];
[Rep,Val] = hist(x,unique(x));
gives:
Rep = [2 4 4 2]
Val = [1 2 3 4]
但在 Numpy 中:
import numpy as np
x = np.array([1,2,2,2,1,4,4,2,3,3,3,3])
Rep, Val = np.histogram(x,np.unique(x))
gives:
>>>Rep
array([2, 4, 6])
>>>Val
array([1, 2, 3, 4])
如何获得与 MATLAB 相同的结果?