07-29-2019 04:10 AM
Hi all,
I have a 2D array that is formed of 1D arrays of data stacked together. I'd like to perform some functions (just basic math really) on each 1D array.
I know I can use indexing into a for loop to do this one array at a time, but I was wondering if there was a way of doing the same maths on each row of a 2D array (a 1D array) simultaneously?
As an extra, if this is possible, is it doable for an unknown size 2D array (with reasonable size limits)?
Solved! Go to Solution.
07-29-2019 04:33 AM
Hi KieranW,
For loops support iteration parallelism: right click on the loop edge and the option should be in the pop-up menu. When enabled, you get an additional terminal on the loop as shown here. I've never used this feature so can't really comment on any possible pitfalls but I'm sure other contributors can weigh in as necessary.
Andy
07-29-2019 04:44 AM
07-29-2019 05:20 AM
Ah this is great - exactly what I'm looking for thank you.
07-29-2019 05:21 AM
In principle this would work but the maths includes summing each 1D array and dividing it by its sum so trying to do this using arrays would just hurt my head...
07-29-2019 05:43 AM
@KieranW wrote:
In principle this would work but the maths includes summing each 1D array and dividing it by its sum so trying to do this using arrays would just hurt my head...
That's a very easy calculation: It's 1.
Or do you mean to divide the sum of each array with the total of all?
/Y
07-29-2019 05:50 AM
Is this what you are looking for? You can also add in the parallel looping suggested up above and it should all work as desired
07-29-2019 05:56 AM
This is the basic principle yes but as I said in the original post I was familiar with using indexing and for loops. It was the parallel processing suggested above I was after.
07-29-2019 06:00 AM
It's not the maths I'm struggling with. It was literally just the parallelism solved in the first response to this post. I was giving the summing of a 1D array as an example of why I needed to split the original 2D array into the constituent 1D arrays.