Inverse of numpy's bincount function

后端 未结 3 1002
清酒与你
清酒与你 2020-12-11 08:13

Given an array of integer counts c, how can I transform that into an array of integers inds such that np.all(np.bincount(inds) == c) i

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 08:55

    no numpy needed :

    c = [1,3,2,2]
    reduce(lambda x,y: x + [y] * c[y], range(len(c)), [])
    

提交回复
热议问题