Re: Add array elements efficiently

778 2
Showing results for 
Search instead for 
Did you mean: 
8 - Airtable Astronomer
8 - Airtable Astronomer

HI there - I am wanting to try to efficiently add various combos of multiple arrays to try to find a set that has non-zero elements.

This is an abbreviated version. I have a set of ~300 arrays x 30 elements in each array to try to find a complete set of sets.

let arr1 = [0, 1, 0, 1, 0, 1, 0, 0, 1, 0]

let arr2 = [1, 0, 0, 1, 1, 1, 1, 0, 0, 1]
let arr3 = [1, 1, 0, 1, 1, 1, 0, 0, 0, 0]
let arr4 = [0, 1, 0, 0, 1, 1, 0, 1, 0, 0]

Assume that instead of individual arrays, there is one matrix and we are adding the combination of columns in matrices to find a matching set.

3 Replies 3

It’s nice to see that data science is drifting into Airtable conversations because it suggests there are actually lots of data worth sciencing about. :winking_face:

I’m not an expert in matters of complex array handling in javascript, but I believe you are describing why tuples are so powerful. Indeed, I think you are trying to do what tuples do insanely fast - like this example. If I’m right, you need an n-dimensional array.

If tuples are the right approach for your objective, you are a bit out of luck because javascript doesn’t support tuples, or does it?

When faced with this type of challenge I tend to lean on JSON objects as a way to perform aggregations like this. With a given key, it’s easy to traverse the array collections instantiating a unique and then summing totals or averages for numeric data types. This is typically the world of ElasticSearch and Python (numpy) but objects occasionally provide a workable outcome.

What if… you aggregated the sets and computed the average sum of each array value while also building a unique JSON object for each set collection. When complete, you would need only discard any objects with an average of zero in any element, leaving you with all the sets that are non-zero.

Bottom line - this question is more likely to get some helpful suggestions when published in StackOverflow or presented to @JonathanBowen. :winking_face:

Thanks, Bill.

I am updating to clarify that I am actually using a matrix and want to add all the combos of each column together.

Thanks for tagging someone who is likely to know and understand.

@Rose_Haft1 - Can you explain some more about what you are trying to do or link to a resource which explains in more detail?