Last active
June 13, 2019 18:49
-
-
Save el0911/e8bce66c2d0aae01562308d4df743302 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createDataSet=(maxNum)=>{ | |
let inputs = [] | |
let targets = [] | |
for(let i = 0 ;i<=maxNum;i++){ | |
let binarry = (i).toString(2) | |
if (binarry.length>10){ | |
throw 'this number has a binary representation longer than 10' | |
return -1 | |
console.log('this number has a binary representation longer than 10') | |
} | |
if(binarry.length!=10){ | |
const remain = 10 - binarry.length | |
for (let j = 0;j<remain;j++){ | |
binarry = '0'+binarry | |
} | |
} | |
inputs.push(binarry.split('').map(Number)) | |
if(i%2==0){ | |
//even number | |
targets.push(1) | |
}else{ | |
targets.push(0) | |
} | |
} | |
return {inputs,targets} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment