Hi Forum,
I would like to multiply all elements in a list and make a new list of the result.
Is there a way to do this by manipulating the list directly?
Thanks!
multiply all element of list
Hi Forum,
I would like to multiply all elements in a list and make a new list of the result.
Is there a way to do this by manipulating the list directly?
Thanks!
@cfry I don't think so...... but it's a simple operation using the list-abs library....
list-apply.zip.... with [list-drip] doing all the work as usual.
All vanilla.
David.
@cfry Here is an improved list-apply, it uses [list store] so does not iterate the list, just does the math on each list item individually. As a bonus you can change the function on the fly to most anything. No time for an in depth help file, but this should suffice.
Edit; this requires at least pd 0.52 for the [list store] [set( message.
list-apply.pd
list-apply-help.pd
Here’s a dynamic version so the same object can be used with all arithmetic operators.
It uses [else/dollsym] but that can be easily removed.
Hope this helps,
list_op.pd
Sorry just realized @oid has a much better solution
Thank you all, this will come handy. Then I will replace my awkward improvisation ->
For simple operations it would also be possible to use [expr $f1 $1 $f2] instead of dynamic patching.
@ingox I usually use something like [list-abs/list-map]
(possibly using [drip]
from zexy inside [list-map]
instead of [list-drip]
for efficiency)
@ingox Why not just [$1 $2}? Does [expr] offer anything extra in that case other than increased overhead?
@oid True.
Oops! Looks like something went wrong!