Forum Discussion
PeterBartholomew1
Dec 24, 2021Silver Contributor
Accumulating arrays
Spreadsheets are the home of the 2D array. On closer examination most of the 2D arrays that one sees are actually 'arrays of arrays', that is a 1D array nested within a list of similar arrays. At p...
PeterBartholomew1
Dec 29, 2021Silver Contributor
I think scan_thunks was missing a closing parenthesis
= LAMBDA(init_vals_arr,array,fn,
LET(
rows_, ROWS(array),
cols_, COLUMNS(array),
thunk, LAMBDA(x,LAMBDA(x)),
row_thunks, BYROW(array, thunk),
scan_thunks,
MAP(init_vals_arr, row_thunks,
LAMBDA(init,row_thunk,
thunk(SCAN(init,row_thunk(),fn)))),
MAKEARRAY(rows_,cols_,
LAMBDA(i,j,
INDEX( INDEX(scan_thunks,i,1)(), 1, j)
)
)
)
)(initial,array,Sumλ)
tboulden I am going to have to work hard to catch up with you!! (grin)
SergeiBaklan
Dec 29, 2021Diamond Contributor
Interesting discussion about thunking, have to learn more.
So far modified a bit my initial variant by adding inits to SCAN
scanByRows = LAMBDA(starts, data, fn,
MAKEARRAY(
ROWS(data),
COLUMNS(data),
LAMBDA(r, c,
// SCAN accumulates data for each row
// and outer INDEX returns result for
// each column of such row
INDEX(
SCAN(
INDEX(starts, r),
INDEX(data, r, 0),
LAMBDA(a, v, fn(a, v))
),
1,
c
)
)
)
);