Sum Numbers in a List

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?

Hi, Glen.

I always use combine to aggregate data. Then you could make an average block like this:

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:

which gets the same result:

Is that what you were looking for?

This is perfect. (Thanks!)

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?

Hi!
Or you can use "keep" to select the items you want:

Joan

Great response, Joan! Just as I was about to.. haha!

Lots of ways to do this. I like this one:

... 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.)

Oooh! I love this one, Brian, didn't even think of something so simple and elegant. Beautiful!

Thanks!