看一下
np.bincount:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.bincount.html
import numpy as npx = np.array([1,1,1,2,2,2,5,25,1,1])y = np.bincount(x)ii = np.nonzero(y)[0]
接着:
zip(ii,y[ii]) # [(1, 5), (2, 3), (5, 1), (25, 1)]
要么:
np.vstack((ii,y[ii])).T# array([[ 1, 5], [ 2, 3], [ 5, 1], [25, 1]])
或者您想将计数和唯一值结合起来。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)