1
、私が持っていると事前にB元の並べ替えを維持しながら、配列のN個の最高数値を取得するには? N最高番号の例えば
a = np.array([12.3,15.4,1,13.3,16.5])
b = ([15.4,13.3,16.5])
感謝を取得したい= 3
Nを言うことができます。
、私が持っていると事前にB元の並べ替えを維持しながら、配列のN個の最高数値を取得するには? N最高番号の例えば
a = np.array([12.3,15.4,1,13.3,16.5])
b = ([15.4,13.3,16.5])
感謝を取得したい= 3
Nを言うことができます。
も、この上の私の感想:
var a = [12.3,15.4,1,13.3,16.5], n = 3, x = 0, c =[]; // c - the resulting array
var b = a.slice(); // copy the original array to sort it
for(var i = 1; i < b.length; i++) { // insertion sorting of the copy
var temp = b[i];
for(var j = i - 1; j >= 0 && temp > b[j]; j--) b[j + 1] = b[j];
b[j + 1] = temp;
}
for(var i = 0; i < a.length; i++) { // creating the resulting array
for(var j = 0; j < n; j++) {
if(a[i] === b[j]) {
c[x] = a[i]; x++; // or just c.push(a[i]);
}
}
}
console.log(c);
例はJavaScriptで書かれており、やや簡単です、しかし、実際には、それはかなりの言語に依存しないで、仕事をしている。