Re: Average of 2-D array

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

I have a two-dimensional sequence of integers (100 in all, arranged 10x10).

Let's call it x.

I can get math:sum(x) easily, it adds them up regardless of nesting. But stats:average(x) doesn't work that way.

I could get the average by dividing the sum by 100,but who knows if the array will always be that size? length(x) does not return the actual number of elements, it returns 10.

/usr/local/share/euphoria/include/std/stats.e:490 in function sum() type_check failure, result_ is {1,2,3,4,5,6,7,8,9,10}

Am I overlooking a function in either math or stats? Or a function to get the actual number of elements in the array?

If you want it to average the atoms regardless of nesting, why not use stdseq:flatten() to create a sequence of atoms (with no nesting) and then call stats:average() on that?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu