Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate the sum of matrices in a list or a 3D array

Tags:

arrays

list

r

Given a list (length = n) of 2x2 matrices, how do I calculate the sum of all those matrices (and get a 2x2 matrix) ?

How can I do it, if instead of a list I have those matrices in a (2 x 2 x n) dimensional array ?

like image 297
Brani Avatar asked Aug 16 '10 11:08

Brani


People also ask

How do you find the number of elements in a 3D array?

The total number of elements that can be stored in a multidimensional array can be calculated by multiplying the size of all the dimensions. For example: The array int x[10][20] can store total (10*20) = 200 elements. Similarly array int x[5][10][20] can store total (5*10*20) = 1000 elements.

How do you find the sum of items in an array?

You can find the sum of all elements in an array by following the approach below: Initialize a variable sum to store the total sum of all elements of the array. Traverse the array and add each element of the array with the sum variable. Finally, return the sum variable.

How do you find the sum of a 2D array?

The sum of each element of the 2D array can be calculated by traversing through the matrix and adding up the elements.

How do you sum a 3D array in Java?

It's a += b ( a = a + b ), not a =+b (see your second loop).


1 Answers

Sum of matrices in a list:

Reduce("+", matrix_list)
like image 76
rcs Avatar answered Sep 30 '22 00:09

rcs