Hi !
I have a list and i want to know the element there that repeats the most. Anyone knows how can I do this ?
ie:
list: 5 5 5 5 4 3 4 5 5
result: 5
Thanks in advance,
Leandro
List element repetitions
Hi !
I have a list and i want to know the element there that repeats the most. Anyone knows how can I do this ?
ie:
list: 5 5 5 5 4 3 4 5 5
result: 5
Thanks in advance,
Leandro
ok, this is for sure the most complicated way to solve the problem you described, but i'm a noob in pd and i don't know all the objects and routines you can use. but it works so far, but you always have to adjust the length of the list if you change it.
have a look at the attached patch, but don't laugh about it....
just bang the message box with the list in it, and see what it does....
Hey, super thanks, i used some of your work to do it, I'll post it on the forum when i finish my patch (if i ever :P)
Thanks again !
Leandro.
Hi,
I was thinking about the problem and of how tricky it is in PD related to other languages... This is what in statistics is called mode, that is in a collection the object which occurs most (see wikipedia)
I tried a version which is a little more "general" than the one proposed (at least for numbers).
Lorenzo
Hi,
This is an interesting solution to the problem. I was using a modification of the other patch posted, but yours seems more efficient.
I'm having some latency problems in my patch, so I will definitly give it a try, thanks !.
Have you seen the other solution ? Do you think yours has a better performance ?
Cheers,
Leandro.
I'm not sure about efficiency... I think this solution is somewhat more general.
What made me think of having a go at a different solution, was the fact that the proposed one is limited to the range 0-10 and that you have to know the length of the list prior (although you could solve this with
dynamically).
Lorenzo
wow, this is much more elegant than my patch!!! nice one!
edit: but it's really not that trivial, as it sounds! i guess, in cases like this one my lack of experience with pd is more obvious! i just don't know half of the abstractions u have used in your patch!
@toxonic said:
edit: but it's really not that trivial, as it sounds! i guess, in cases like this one my lack of experience with pd is more obvious! i just don't know half of the abstractions u have used in your patch!
Well, I know how you feel, and I'm sure I know a quarter of the abstractions the gurus around here know, I'm learning too.
Anyway what gave me the main hint was the algorithm on the wikipedia page I cited, especially about sorting the list first... I also draft a function for mode in python...
I guess for these cases which are easily solved in more "traditional" programming languages and less "experimental" it's good to first think of the algorithm and then try to render it in PD.
All the best
Lorenzo.
this wouldn't let me go....
i worked a bit further on it and built a new patch - mainly with a similar result like yours but i guess it's a bit more little.
indeed, the sorting of the list is an important point - so now, it would be possible with some more work to find out the biggest or the smallest number in case that there are more then one modal number in the list. just use [sort] in descending mode and change (at least) one of the compare objcects, than it shoul be possible...
Oops! Looks like something went wrong!