1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import * as tf from "@tensorflow/tfjs"; let t0 = tf.tensor([1,2]); t0.print(); console.log(t0); let t1 = tf.tensor([[1,2,3],[3,4,5]]); t1.print(); console.log(t1); let t2 = tf.tensor([[[1]]]); t2.print(); console.log(t2);
let input = [1,2,3,4]; let w = [[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]; let output = [0,0,0,0];
w.forEach((i,index1)=>{ input.forEach((j,index2)=>{ output[index1] += i[index2]*j; }) }) console.log(output);
tf.tensor(w).dot(tf.tensor(input)).print(); tf.dot(w,input);
|