  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Average of each two columns in an array  » arrays » Average of each two columns in an array

By : Dimuth Jayasuriya
Date : November 21 2020, 11:01 PM code :
``````arr=[2 3 4 5 6 7 8 9 1 2 3 4];

arr2=[1 1];

A=conv(arr,arr2)/2;

mean2=A(2:2:end-1)

plot(mean2)
``````
``````arr=[2 3 4 5 6 7 8 9 1 2 3 4 6];

arr2=[1 1];

A=conv(arr,arr2)/2;

if mod(length(arr),2) == 1;

mean2=[A(2:2:end-1) arr(end)]

else
mean2=[A(2:2:end-1)]
end

plot(mean2)
`````` ## 2 Dimensional array and Print out average of the Columns and Rows

By : tweetbro
Date : March 29 2020, 07:55 AM
this will help Ok, I'll see what I can add.
Defines are not written like that, and by convention should be all upper case
code :
``````#define ROWS 3
#define COLUMNS 5
``````
``````float **array;
``````
``````ROWS * sizeof(float*)
``````
``````COLUMNS * sizeof(float)
``````
``````for(row 1..3)
array[row] = malloc(...)
for(col 1..5)
fscanf(value)
array[row][col] = value
`````` ## Displaying Average of 3 Different Columns in Array

By : roboman6
Date : March 29 2020, 07:55 AM
I hope this helps . IndexOutOfRangeException is thrown when you attempt to access an element of an array that doesn't exist.
Note that you have initialized scores as follows:
code :
``````uint[,] scores = new uint[,] { };
``````
``````scoresRowTotal[i] += scores[i, j];
``````
``````uint[,] scores = new uint[,] { {0, 1}, {2, 3} };
``````
`````` 
 
`````` ## Average of bidimensional array's columns with array.map()

By : S_J
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have an array that looks like this: , You can use reduce() and forEach() to return result.
code :
``````var array = [
[1, 3, 9],
[4, 6, 8],
[3, 7, 5],
[2, 8, 4]
];

var sums = array.reduce(function(r, e, i) {
e.forEach((a, j) => r[j] = (r[j] || 0) + a)
return r;
}, [])

console.log(sums)``````
``````var array = [
[1, 3, 9],
[4, 6, 8],
[3, 7, 5],
[2, 8, 4]
];

var sums = array.reduce(function(r, e, i) {
e.forEach((a, j) => r[j] = (r[j] || 0) + a)
if (i == array.length - 1) r = r.map(el => el / array.length);
return r;
}, [])

console.log(sums)`````` ## Average a columns in a 2D array with functional programming

By : VBnoob21
Date : March 29 2020, 07:55 AM
wish helps you As an exercise in functional programming, I've decided to go through one of my projects and replace functions containing for loops with Array.prototype's higher order functions such as map and reduce. , Try this example with reduce and forEach functions:
code :
``````let a = [
[0.6,  4.0, -0.5],
[3.0, -0.5, -0.1],
[1.0, -0.2, -0.8],
[7.0, -0.5, -0.8]
];

let b = a.reduce((acc, cur) => {
cur.forEach((e, i) => acc[i] = acc[i] ? acc[i] + e : e);
return acc;
}, []).map(e => e / a.length);

console.log(b);``````
``````let a = [
[0.6,  4.0, -0.5],
[3.0, -0.5, -0.1],
[1.0, -0.2, -0.8],
[7.0, -0.5, -0.8]
];

let b = a.map((col, i) => a.map(row => row[i]).reduce((acc, c) => acc + c, 0) / a.length);

console.log(b);`````` ## Take average of columns in a numpy array

By : Paolo Rigobello
Date : March 29 2020, 07:55 AM
it helps some times I have taken data from a csv file using numpy. numpy array has dimensions : 100*20. How do i take average of columns (say col 3,5,8) and replace them with a new column containing average of these 3 cols 