본문 바로가기

JAVASCRIPT

JAVASCRIPT ) 부울행렬의 연산

 

 

부울 합

let f = [
    [1,0],
    [1,0],
]

let g = [
    [0,1],
    [1,0]
]

let result2 = []

for(let i=0; i<f.length; i++){
    let temp = []
    for(let j=0; j<f[0].length; j++){
        temp.push(0);
    }
    result2.push(temp);
}

for(let i=0; i<f.length; i++){
    for(let j=0; j<f[0].length; j++){
        result2[i][j] = f[i][j] + g[i][j]
        if(result2[i][j] > 1){
            result2[i][j] = 1;
        }
    }
}
console.log(result2);

 

 

 

부울 교차

let f = [
    [1,0],
    [1,0],
]

let g = [
    [0,1],
    [1,0]
]

let result2 = []

for(let i=0; i<f.length; i++){
    let temp = []
    for(let j=0; j<f[0].length; j++){
        temp.push(0);
    }
    result2.push(temp);
}

for(let i=0; i<f.length; i++){
    for(let j=0; j<f[0].length; j++){
        result2[i][j] = f[i][j] * g[i][j];
    }
}
console.log(result2);

 

 

 

부울곱

let c = [
    [1,0],
    [0,1],
    [1,0]
]
let d = [
    [1,1,0],
    [0,1,1],
]

let result = []
for(let i=0; i<c.length; i++){
    let tempA = [];
    for(let j=0; j<d[0].length; j++){
        tempA.push(0);
    }
    result.push(tempA);
}
for(let i=0; i<c.length; i++){
    for(let j=0; j<d[0].length; j++){
        for(let k=0; k<c[0].length; k++){
            result[i][j] += c[i][k] * d[k][j];
            if(result[i][j] > 1){
                result[i][j] = 1;
            }
        }
    }
}

console.log(result);

 

반응형