# Re: [sc-users] Similarity Clumping

Ah, that's an interesting approach.. thanks!
I'm still a little unsure about one last thing, though:

If things are only compared to the previous value, this could produce very long sequences of correlated numbers..

Again, it might be better for me to illustrate:

a = [0.3, 0.31, 0.32, 0.33]
and the threshold is at 0.1...
The difference between 0.3 and 0.31 is within the threshold, but then the .separate method compares 0.31 to 0.32.  Is there a way to make the method only compare to the first input value?

On Sat, Nov 30, 2019 at 2:16 PM <spluta@xxxxxxxxx> wrote:
You could add the indices to each array:

a = [0.4, 0.42, 0.45, 0.46, 0.6, 0.7];
a = a.collect({|item, i| [item, i]});
b = a.separate { |a, b| (b[0] - a[0]) >= 0.02 };

On November 30, 2019 at 6:56:32 PM, jables.deutsch@xxxxxxxxx (jables.deutsch@xxxxxxxxx) wrote:

Thanks, Newton -
Is there any way to preserve the indices, like the "order" method does, also?

On Sat, Nov 30, 2019 at 4:29 AM Armstrong, Newton <Newton.Armstrong.1@xxxxxxxxxx> wrote:
a = [0.4, 0.42, 0.45, 0.46, 0.6, 0.7];
b = a.separate { |a, b| (b - a) >= 0.02 };

> On 30 Nov 2019, at 6:15am, jables.deutsch@xxxxxxxxx wrote:
>
> Hi all -
>
> I'd like to take an array and break it into sub-arrays, based on the difference between values.. It might be easier to illustrate:
>
> I have an array:
> a = [0.4, 0.42, 0.45, 0.46, 0.6, 0.7];
> And I want to set a threshold of difference - in this case: 0.02.
> newArray = [[0.4, 0.42], [0.45, 0.46], [0.6], [0.7]];
>
> Is there a function that does this kind of sorting intrinsically?  Can anyone suggest an approach?
>
>
>
>
>

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/