Find indexes of repeated elements in an array (Python, NumPy)

前端 未结 5 1230
甜味超标
甜味超标 2020-12-20 14:52

Assume, I have a NumPy-array of integers, as:

[34,2,3,22,22,22,22,22,22,18,90,5,-55,-19,22,6,6,6,6,6,6,6,6,23,53,1,5,-42,82]

I want to find

5条回答
  •  伪装坚强ぢ
    2020-12-20 15:23

    There really isn't a great short-cut for this. You can do something like:

    mult = 5
    for elem in val_list:
        target = [elem] * mult
        found_at = val_list.index(target)
    

    I leave the not-found exceptions and longer sequence detection to you.

提交回复
热议问题