COLPAIRWISE

Purpose:

Applies a function to all pairwise column combinations from one or two input series.

Syntax:

COLPAIRWISE("funname", x, y, opt1, opt2, ..., optN)

"funname"

-

A string, the name of the processing function.

x

-

A series or array, the input series.

y

-

Optional. A series or array. Defaults to x.

optN

-

Optional. Anything, zero or more optional arguments supported by funname.

Returns:

A multi-column series. If f is the function name and x is the input series, the columns of the multi-column result are:

 

C11, C12, ..., C1N, C21, C22, ..., C2N, ..., CN1, CN2, ..., CNN

 

where Cab is the result of f(col(x, a), col(x, b))

 

For two input series x and y, the resulting columns are:

 

C11, C12, ..., C1N, C21, C22, ..., C2N, ..., CN1, CN2, ..., CNN

 

where Cab is the result of f(col(x, a), col(y, b))

Example:

W1: ravel(1..12, 4);table

W2: colpairwise("plus", w1)

 

W1 == {{1, 5,  9},

       {2, 6, 10},

       {3, 7, 11},

       {4, 8, 12}}

 

W2 == {{2,  6, 10,  6, 10, 14, 10, 14, 18},

       {4,  8, 12,  8, 12, 16, 12, 16, 20},

       {6, 10, 14, 10, 14, 18, 14, 18, 22},

       {8, 12, 16, 12, 16, 20, 16, 20, 24}}

 

The result contains a total of 9 columns. The first 3 columns are equivalent to:

 

col(w1,1)+col(w1,1), col(w1,1)+col(w1,2), col(w1,1)+col(w1,3)

 

The next three columns are equivalent to:

 

col(w1,2)+col(w1,1), col(w1,2)+col(w1,2), col(w1,2)+col(w1,3)

 

And the final three columns are equivalent to:

 

col(w1,3)+col(w1,1), col(w1,3)+col(w1,2), col(w1,3)+col(w1,3)

Example:

W1: ravel(1..12, 4);table

W2: w1

W3: colpairwise("plus", w1, w2)

 

W1 == {{1, 5,  9},

       {2, 6, 10},

       {3, 7, 11},

       {4, 8, 12}}

 

W2 == {{1, 5,  9},

       {2, 6, 10},

       {3, 7, 11},

       {4, 8, 12}}

 

W3 == {{2,  6, 10,  6, 10, 14, 10, 14, 18},

       {4,  8, 12,  8, 12, 16, 12, 16, 20},

       {6, 10, 14, 10, 14, 18, 14, 18, 22},

       {8, 12, 16, 12, 16, 20, 16, 20, 24}}

 

Same as above, except two identical input series are provided.

Example:

W1: ravel(1..12, 4);table

W2: ravel(1..12, 3);table

W3: colpairwise("plus", w1, w2)

W4: colpairwise("plus", w2, w1)

 

W1 == {{1, 5,  9},

       {2, 6, 10},

       {3, 7, 11},

       {4, 8, 12}}

 

W2 == {{1, 4, 7, 10},

       {2, 5, 8, 11},

       {3, 6, 9, 12}}

 

W3 == {{2, 5,  8, 11,  6,  9, 12, 15, 10, 13, 16, 19},

        4, 7, 10, 13,  8, 11, 14, 17, 12, 15, 18, 21},

        6, 9, 12, 15, 10, 13, 16, 19, 14, 17, 20, 23},

        4, 4,  4,  4,  8,  8,  8,  8, 12, 12, 12, 12}}

 

W4 == {{2,  6, 10, 5,  9, 13,  8, 12, 16, 11, 15, 19},

       {4,  8, 12, 7, 11, 15, 10, 14, 18, 13, 17, 21},

       {6, 10, 14, 9, 13, 17, 12, 16, 20, 15, 19, 23},

       {4,  8, 12, 4,  8, 12,  4,  8, 12,  4,  8, 12}}

 

W1 is a 4x3 array.

W2 is a 3x4 array.

W3 is a 4x12 array.

W4 is a 4x12 array.

 

W3 adds each column of W1 to each column of W2. The result is a 4×12 matrix.

 

W4 performs the same operation with the input arguments reversed. The result is also 4×12, but with a different column order.

 

The output row count equals the maximum row count of the input series. Shorter series are zero-padded during computation.

 

The output column count is the product of the column count of the two input series.

Example:

W1: ravel(1..12, 4);table

W2: ravel(1..12, 3);table

W3: colpairwise("times", w1, w2)

W4: colpairwise("times", w2, w1)

 

W1 == {{1, 5,  9},

       {2, 6, 10},

       {3, 7, 11},

       {4, 8, 12}}

 

W2 == {{1, 4, 7, 10},

       {2, 5, 8, 11},

       {3, 6, 9, 12}}

 

W3 == {{1,  4,  7, 10,  5, 20, 35, 50,  9, 36, 63,  90},

        4, 10, 16, 22, 12, 30, 48, 66, 20, 50, 80, 110},

        9, 18, 27, 36, 21, 42, 63, 84, 33, 66, 99, 132},

        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0}}

 

W4 == {{1,  5,  9,  4, 20, 36,  7, 35, 63, 10, 50,  90},

       {4, 12, 20, 10, 30, 50, 16, 48, 80, 22, 66, 110},

       {9, 21, 33, 18, 42, 66, 27, 63, 99, 36, 84, 132},

       {0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0}}

 

Same as above, except the pairwise products are computed. Since shorter series are zero-padded, the final row of both W3 and W4 contains all zeros.

Example:

setstripchartcolormode(w1..w4, 1);

W1: gsweep(10240, 1/10240, 10, 1000);ravel(w0, 5120);stripchart

W2: w1*w1

W3: cpsd(w1, w2, 1024, 512, 2048, "mag");stripchart;loglog

W4: colpairwise("cpsd", w1, w2, 1024, 512, 2048, "mag");stripchart;loglog

 

 

The stripchart color mode is set to assign each trace in W1, W2, W3 and W4 to a separate color.

 

W1 contains two columns of a swept sine wave.

 

W2 squares both series in W1.

 

W3 computes the cross-power spectral density of the columns of W1 and W2. Optional CPSD arguments are specified. The result is the CPSD of W1 column 1 and W2 column 1, and the CPSD of W1 column 2 and W2 column 2, for a total of 2 columns.

 

W4 computes the CPSD of all column pairs using the same optional arguments. The result is 4 columns:

 

Column 1: cpsd(col(w1, 1), col(w2, 1), 1024, 512, 2048, "mag")

Column 2: cpsd(col(w1, 1), col(w2, 2), 1024, 512, 2048, "mag")

Column 3: cpsd(col(w1, 2), col(w2, 1), 1024, 512, 2048, "mag")

Column 4: cpsd(col(w1, 2), col(w2, 2), 1024, 512, 2048, "mag")

 

Note that column 1 of W4 matches column 1 of W3 and column 4 of W4 matches column 2 of W3.

Remarks:

COLPAIRWISE applies a specified processing function to every combination of column pairs from one or two multi-column input series. Useful for generating pairwise transformations, comparisons, or interactions across columns.

 

The output column order is row-major: for each column in x, all pairings with columns in y are evaluated.

 

The function funname must accept two series inputs and return a single series output.

 

For a single input series x, the number of output columns is numcols(x) * numcols(x). The number of output rows is numrows(x).

 

For two input series x and y, the number of output columns is numcols(x) * numcols(y). The number of output rows is max(numrows(x), numrows(y)).

 

Optional arguments are passed through unchanged to funname.

See Also:

COLREDUCE

FEVAL

ITERATE

LOOP