PAIRWISE

PAIRWISE(array_1,array_2,fn)
array_1
an array to be treated as a list of row vectors
array_2
an array to be treated as a list of column vectors

Pairwise function application between two arrays.

tboulden

Board Regular
Joined
Jan 14, 2021
Messages
73
Office Version
  1. 365
Platform
  1. Windows
PAIRWISE leverages MAKEARRAY to lift complex formulas across an array of rows and an array of columns.

Excel Formula:
=LAMBDA(array_1,array_2,fn,
  MAKEARRAY(
    ROWS(array_1),
    COLUMNS(array_2),
    LAMBDA(i,j,
      LET(
        cols_array_1,COLUMNS(array_1),
        rows_array_2,ROWS(array_2),
        fn(
          INDEX(array_1,i,IF(cols_array_1=1,1,SEQUENCE(,cols_array_1))),
          INDEX(array_2,IF(rows_array_2=1,1,SEQUENCE(rows_array_2)),j)
        )
      )
    )
  )
)

LAMBDA_pairwise_thunks_summarize_pivot.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACAD
1"+" lifts over 1d arrays=B3#+C2#"=" lifts over arrays=O3#=P2#
21234=pairWise(B3#,C2#,LAMBDA(x,y,x+y))4321=pairWise(O3#,P2#,LAMBDA(x,y,x=y))
3123452345TRUE1FALSEFALSEFALSETRUEFALSEFALSEFALSETRUETRUE
42345634562FALSEFALSETRUEFALSEFALSEFALSETRUEFALSE
53456745673FALSETRUEFALSEFALSEFALSETRUEFALSEFALSE
64567856784TRUEFALSEFALSEFALSETRUEFALSEFALSEFALSE
7
8"&" lifts over arrays=B10#&C9#Complex formulae won’t lift=IF(ISEVEN(O10#),REPT(P9#,O10#),"")
9EFGH=pairWise(B10#,C9#,LAMBDA(x,y,x&y))ABCD=pairWise(O10#,P9#,LAMBDA(x,y,IF(ISEVEN(x),REPT(y,x),"")))
10AAEAFAGAHAEAFAGAHTRUE1#VALUE! 
11BBEBFBGBHBEBFBGBH2AABBCCDD
12CCECFCGCHCECFCGCH3
13DDEDFDGDHDEDFDGDH4AAAABBBBCCCCDDDD
14
15"+" doesn't lift over >1d=B18#+D16#
1631214=pairWise(B18#,D16#, LAMBDA(row_,col_,SUM(row_,col_)))1Ared1Ared=REDUCE( , pairWise(O16#,TRANSPOSE(Q16#), LAMBDA(x,y, thunkIt(hStack(x,y)))), LAMBDA(stacked,thunk, vStack( IFERROR(stacked(),stacked), thunk())))
17127102Bblue1Ablue
188191131#N/A424651TRUE3Cgreen1Agreen
192171424#N/A3438432Bred
20146#N/A#N/A#N/A3539442Bblue
2176#N/A#N/A#N/A2832372Bgreen
223Cred
234246513Cblue
243438433Cgreen
25353944
26283237
pairWise
Cell Formulas
RangeFormula
C2:F2C2=SEQUENCE(,4)
H1,U8,H8,U1H1=FORMULATEXT(C3)
H2,U9,H9,U2H2=FORMULATEXT(H3)
P2:S2P2=SEQUENCE(,4,4,-1)
B3:B6,O10:O13,O3:O6B3=SEQUENCE(4)
C3:F6C3=B3#+C2#
H3:K6H3=pairWise(B3#,C2#,LAMBDA(x,y,x+y))
L3,L10L3=AND(C3#=H3#)
P3:S6P3=O3#=P2#
U3:X6U3=pairWise(O3#,P2#,LAMBDA(x,y,x=y))
Z3Z3=AND(P3#=U3#)
C9:F9C9=CHAR(SEQUENCE(,4,69,1))
P9:S9P9=CHAR(SEQUENCE(,4,65,1))
B10:B13B10=CHAR(SEQUENCE(4,1,65,1))
C10:F13C10=B10#&C9#
H10:K13H10=pairWise(B10#,C9#,LAMBDA(x,y,x&y))
P10P10=IF(ISEVEN(O10#),REPT(P9#,O10#),"")
U10:X13U10=pairWise(O10#,P9#,LAMBDA(x,y,IF(ISEVEN(x),REPT(y,x),"")))
D16:F17D16={3,12,14;12,7,10}
H15H15=FORMULATEXT(D18)
H16H16=FORMULATEXT(H18)
O16:P18O16={1,"A";2,"B";3,"C"}
Q16:Q18Q16={"red";"blue";"green"}
S16:U24S16=REDUCE( , pairWise(O16#,TRANSPOSE(Q16#), LAMBDA(x,y, thunkIt(hStack(x,y)))), LAMBDA(stacked,thunk, vStack( IFERROR(stacked(),stacked), thunk())))
W16W16=FORMULATEXT(S16)
B18:C21B18={8,19;2,17;14,6;7,6}
D18:F21D18=B18#+D16#
H18:J21H18=pairWise(B18#,D16#, LAMBDA(row_,col_,SUM(row_,col_)))
L18L18=AND(MAP(H18#,H23:J26,LAMBDA(x,y,x=y)))
H23:J26H23=SUM($B18:$C18,D$16:D$17)
Dynamic array formulas.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top