.net - Elegant averaging of arrays from different instances of an object in C# -
.net - Elegant averaging of arrays from different instances of an object in C# -
i have list of objects of same type each has property array of floats. taking list input, easiest way homecoming new array average of arrays in list?
the input objects this:
class mydatas { float [] datavalues; } ... list<mydatas> inputlist; float [] result; the datavalues arrays guaranteed have same length. each element of result array average of corresponding elements in array of each fellow member of list. example: result[0] = (inputlist[0].datavalues[0] + inputlist[1].datavalues[0] + ... ) / inputlist.count
of course of study brute forcefulness foreach within loop , loop after seems me should doable 1 or 2 lines of linq. advice?
float[] result = inputlist.select(c => c.datavalues) .transpose() .select(r => r.average()) .toarray();
using transpose here.
c# .net arrays linq list
Comments
Post a Comment