Substitute for spreads?

Hi,

is there a node wokring like substitute (String) but for spreads? so, I would like to replace certain values in a spread to my new one.

Like mySpread=(0,1,2,3,4,4,3,2,1,0)
replace all 3 to 7 and 1 to 7
after it mySpread=(0,7,2,7,4,4,7,2,7,0)

i believe a combination of = (Value) , Select (Value) and SetSlice (Spreads) will do the trick.

But theres no single node doing this, dont it?
Currently, Im using big spreads and handle with some bin sizes, so this combination will mutliply my spreads remarkable.
Mmmh, may be I have to stick to substitute…

it would appear kind of hackneyed, but there’s AsString (Value) and AsValue (String) … ;)

but isnt a simple GetSlice (Spreads) what you are looking for? use your spread as the index and prepare a spread like
(0, 7, 2, 7, 4, 5, 6, 7)

and you will get (0,7,2,7,4,4,7,2,7,0).

Use I and a spreaded SetSlice to create the spread.

diki: Yes I did it that way, but a problem occurs if I replace a 9, then it will be replaced in 19 either, because Substitute is looking for a character not a pattern… Thats somehow f…ed

oschatz: This way is working well, but still not the best…
Because Im bound to the highest value in my spread. So, if I have

Like mySpread=(0,10000,20000,30000,40000,40000,30000,20000,10000,0)
replace all 30000 to 7 and 10000 to 7
after it mySpread=(0,7,20000,7,40000,40000,7,20000,7,0)

I have to make a new temporary spread up to 40000 !!! just to replace them.
And its not working with float values, integer only!

Anyway, for me its fine and I will put a substitute spread.node onto wishlist ;)

Thanks

substitute (spreads).zip (2.0 kB)

@frank: agreed. on the other side GetSlice can be implemented quite efficient (its just a multiplication and a memory access), as you dont need to iterate through any lists. So the 40000 spread should not be so bad if (as long as it is constant).

Substituting larger floats can be tricky, as you might run into precision issues. so better round floats beforehand to a suitable precision. and if you round them you can also multiply them to get an integer again.

if you go for the string route, make sure to know the various outputs of the Sift (String) node. this allows you to compare for full strings and get the index of the matching one. And use FormatValue (String) instead of AsString (Value) to avoid precision issues.

Hi oschatz, I tried this, too.
Its faster with high values, but Sift’s text pattern isnt spreadable (sort of), which means: to replace 7 values in a spread of 15, first I have to multiply my 15 values 7 times to search for every text pattern.
Finally, I stick to my first version which is fine for me, despite its Integer and value amount limitation.

There was a missing node in my little workaround, so for someone who might use it - the fixed update.

Substitute (Spreads)_2.zip (2.1 kB)

Maybe this could solve?

http://vvvv.org/tiki-download_file.php?fileId=1704

Bye!

dottore