What is the most efficient way to sum and average a series of numbers in the middle of a list?
The following procedure sums and averages a series of numbers in a list of frequencies obtained from the "Microphone Spectrum" input. (We're using the high, low, and mid-range results to control a light show.) Is there a more efficient way to sum and average a series of numbers within a list?
note that the "numbers" input is of type "number - multiple", i.e. a variadic input. You could also simply specify it to be a list. You can use it on any list - including samples and frequency spectrum bins - by dropping the data reporter onto the arrows:
However, if I want to average Items 3 through 6 (for example) in the List of Frequencies, I would need to extract those items to create a new list to submit to the Average block. I could do that with a For loop (such as the one below), but is there a more efficient way to extract a subset of a list?
... because the indices you choose don't have to be consecutive or monotonic. It's a more general tool. If you build this, note that you have to delete the "1" in the ITEM block as it comes from the palette. (One of my longest-running disagreements with Jens is related to this annoyance, because he rightly sees my idea as a huge change in behavior.)