Array.cumcolumn()

Revision as of 13:53, 4 March 2017 by Joseph (talk | contribs) (Created page with " * << Z3 Home * Z3 Language Documentation * Z%5E3_Array_Manipulation_Member_Functions | Listing of Z3 Array Manipulation Member ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Array.accumulate(FromTotal)

Array.accumulate(FromTotal)

Each element is accumulated using SUM with each element.

Array.cumcolumns(Columns|empty)

Each element is accumulated by columns (for the specified columns,or all if none is specified) using SUM with each element.

Array.cumrows(Rows|empty)

Each element is accumulated by rows for the specified rows, or all if none is specified) using SUM with each element.

Array.cumcolumn(Columns|empty)

Same as Array.cumcolumns

Array.cumrow(Row|empty)

Same as Array.cumrows

Array.accumulatewith(SomeFunction, SomeStartingValue or Parameter List)

Each element is accumulated using given function with each element, and with the starting array as first input (if given).

Array.cumcolumnswith(SomeFunction, SomeStartingValue or Parameter List)

Array.accumulatewith for each column.

Array.cumrowswith(SomeFunction, SomeStartingValue or Parameter List)

Array.cumcolumnwith(SomeFunction, SomeStartingValue or Parameter List)

Array.cumrowwith

Array.prototype.cumulate

Array.accumulatewith with function as NUMSUM



if (!Array.prototype.accumulate) { Array.prototype.accumulate= function(SomeTotal) { var SomeTotalArray=new Array(); for(var i=0;i<this.length;i++) { // this is correct as we can give a starting array of the possible indices as in ArrayFrequencyRank if(typeof SomeTotal == "undefined") { SomeTotal=0; // good starting for addition. // try // { // SomeTotal=this[i]||0; // this is from a starting array if present. // } // catch(err) // { // SomeTotal=0; // } SomeTotalArray.push(SomeTotal); continue; }

if(ISARRAY(this[i])) { var SomeThisRowResult = this[i].accumulate(SomeTotal); // take from last summation of the array accumulation? when in multidimensional situation? // Here it pics the last if it is a number, of the FIRST element in the last array to get the rolled up sum of this dimension. SomeTotal+=ISARRAY(SomeThisRowResult.last())?SomeThisRowResult.last()[0]:SomeThisRowResult.last(); SomeTotalArray.push(SomeThisRowResult); } else { SomeTotal=NUMSUM(SomeTotal,this[i]); //SomeTotal=SomeTotal+this[i]; SomeTotalArray.push(SomeTotal); } } return(SomeTotalArray); } }

if (!Array.prototype.cumcolumns) { Array.prototype.cumcolumns = function() { return(this.transpose().cumrows(ARGS(arguments)).transpose()); } }

if (!Array.prototype.cumrows) { Array.prototype.cumrows= function() { var SomeRows; var rowstoget=ARGS(arguments); rowstoget=rowstoget.flatten(); if(rowstoget.length==0) { SomeRows=this.rows(); // to get all rows. } else { SomeRows=this.rows(rowstoget);//ARGS(arguments)); }

var SomeNewArray=new Array(); for(var i=0;i<SomeRows.length;i++) { SomeNewArray.push(SomeRows[i].accumulate()); } return(SomeNewArray); } } Array.prototype.cumcolumn=Array.prototype.cumcolumns; Array.prototype.cumrow=Array.prototype.cumrows;


if (!Array.prototype.accumulatewith) { Array.prototype.accumulatewith= function(SomeCumulateFunction,SomeCurrentResult) { var SomeTotalArray=new Array(); SomeCumulateFunction=GETFUNCTIONSET(SomeCumulateFunction)[0]; // only one allowed here. combine functions if need be to get other results. //SomeCurrentResult=DEFAULT(SomeCurrentResult,0); for(var i=0;i<this.length;i++) { // kept the original code to aid ArrayFrequencyRank // this is correct as we can give a starting array of the possible indices as in ArrayFrequencyRank // still does not make sense since if ArrayFrequencyRank has [0,0] as incoming. // maybe the approach is to apply function to itself to get a starting value? if(typeof SomeCurrentResult== "undefined") { // interesting starting point, assumes that the incoming function may need the entire row as input? SomeCurrentResult=this[i]; // given for each level SomeTotalArray.push(SomeCurrentResult); continue; } if(ISARRAY(this[i])) { var SomeThisRowResult = this[i].accumulatewith(SomeCumulateFunction,SomeCurrentResult); // if the remaining result is an array, take the last element. why? SomeCurrentResult= SomeCumulateFunction .apply(this,[SomeCurrentResult,ISARRAY(SomeThisRowResult.last())?SomeThisRowResult.last()[0]:SomeThisRowResult.last()]); SomeTotalArray.push(SomeThisRowResult); } else { SomeCurrentResult=SomeCumulateFunction.apply(this,[SomeCurrentResult,this[i]]); SomeTotalArray.push(SomeCurrentResult); } } return(SomeTotalArray); } } if (!Array.prototype.cumcolumnswith) { Array.prototype.cumcolumnswith = function(SomeCumulateFunction, SomeColumns) { return(this.transpose().cumrowswith(SomeCumulateFunction,ARGS(arguments).cdr()).transpose()); } } if (!Array.prototype.cumrowswith) { Array.prototype.cumrowswith= function(SomeCumulateFunction, SomeRows) { //SomeFunction is the car of ARGS SomeRows=this.rows(ARGS(arguments).cdr()); // overrides

var SomeNewArray=new Array(); for(var i=0;i<SomeRows.length;i++) { SomeNewArray.push(SomeRows[i].accumulatewith(SomeCumulateFunction,SomeRows)); } return(SomeNewArray); } } Array.prototype.cumcolumnwith=Array.prototype.cumcolumnswith; Array.prototype.cumrowwith=Array.prototype.cumrowswith;

//Array.prototype.cumulate=Array.prototype.accumulatewith.curry(function(x,y){return(x+y)}) Array.prototype.cumulate=Array.prototype.accumulatewith.curry(NUMSUM)