Hi
When speaking about duplicates for numbers, I'm alway thinking to "np.unique" => here bellow an example. Note at the same time Numpy is fast even for a huge array size.
Paul
When speaking about duplicates for numbers, I'm alway thinking to "np.unique" => here bellow an example. Note at the same time Numpy is fast even for a huge array size.
Paul
import numpy as np MyList=[0, 1, 10, 5, 2, 1, -1, 8, 2, 1, 5, 1, 1, 1, -1] MyList=np.asarray(MyList) UniqueList = np.unique(MyList, return_index=True, return_counts=True) n = np.shape(UniqueList[0])[0] for i in range(n): print(f"for {UniqueList[0][i]} => {UniqueList[2][i]} occurence(s)")Provinding:
Output:for -1 => 2 occurence(s)
for 0 => 1 occurence(s)
for 1 => 6 occurence(s)
for 2 => 2 occurence(s)
for 5 => 2 occurence(s)
for 8 => 1 occurence(s)
for 10 => 1 occurence(s)