powershell 返回数组数组的笛卡尔积

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 返回数组数组的笛卡尔积相关的知识,希望对你有一定的参考价值。

#build the cartesian product for an array of arrays
function CartesianProduct($row, $currCol=0){
    if ($currCol -eq 0){
        $wordIndices = New-Object int[] $row.Length
    }
    $wordIndex = 0
    #walk through the items in the current column
    foreach($word in $row[$currCol]){
        #add the index to the indices for the current column
        $wordIndices[$currCol] =  $wordIndex
        $wordIndex++
        #if we reach the end of the row
        if ($currCol -eq ($row.Length - 1)) {
            $cartesianSet = @()
            $colIndex = 0
            foreach($column in $row){
                #add the items to the result set based on the collected indices
                $cartesianSet += $row[$colIndex][$wordIndices[$colIndex]]
                $colIndex++
            }
            $cartesianSet -join ','
        } 
        #do this for every column
        else {
            CartesianProduct $row ($currCol + 1)
        }
    }
}

以上是关于powershell 返回数组数组的笛卡尔积的主要内容,如果未能解决你的问题,请参考以下文章

查找 JavaScript 数组值的所有组合(笛卡尔积)

使用 PHP 关联数组查找笛卡尔积

js编写一个数组笛卡尔积算法

受限笛卡尔积计算 - PHP

N 个数组的笛卡尔积

SQL 不等式加入返回的笛卡尔积