Jump to content

Add elements of a 2D array every nth arrays

Recommended Posts


I have a 2D nth array, ie:

1  2  3  4  5  6

2  3  7  8  9  4

7  8  3  45  7 1


2  5  1  8  1  5 

I want to take the first three rows, add the elements together and create a new row that will replace the three rows and I want to do this every three rows and create a nth/3 2D array.


Any ideas?


Thank you in advance


Link to post
Share on other sites

When you say that you want to add the first three rows and add the elements together I assume that the sum you are after is not the sum of all the elements in those rows (which would be just one number), but the sum of each subcolumn, or? 

If so, in your example above the first row in the output array will be:

10, 13, 13, 57, 21, 11

There are a lot of ways to do that, and the different ways have different speed and memory efficiency depending on how many columns there are, and how many rows you want to sum. Attached is one alternative (made in LV2015, back-converted to 2012) that seems to be an OK compromise between code simplicity and speed...I'm sure someone will take the challenge and improve it though;)



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.