عمليات TensorFlow
- يضيف
- طرح او خصم
- تتضاعف
- يقسم
- مربع
- إعادة تشكيل
إضافة موتر
يمكنك إضافة موترتين باستخدام tensorA.add (tensorB) :
مثال
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);
// Tensor Addition
const tensorNew = tensorA.add(tensorB);
// Result: [ [2, 1], [5, 2], [8, 3] ]
طرح الموتر
يمكنك طرح موترين باستخدام tensorA.sub (tensorB) :
مثال
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);
// Tensor Subtraction
const tensorNew = tensorA.sub(tensorB);
// Result: [ [0, 3], [1, 6], [2, 9] ]
الموتر الضرب
يمكنك ضرب اثنين من الموترات باستخدام tensorA.mul (tensorB) :
مثال
const tensorA = tf.tensor([1, 2, 3, 4]);
const tensorB = tf.tensor([4, 4, 2, 2]);
// Tensor Multiplication
const tensorNew = tensorA.mul(tensorB);
// Result: [ 4, 8, 6, 8 ]
شعبة موتر
يمكنك قسمة موترين باستخدام tensorA.div (tensorB) :
مثال
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);
// Tensor Division
const tensorNew = tensorA.div(tensorB);
// Result: [ 2, 2, 3, 4 ]
ميدان تنسور
يمكنك تربيع موتر باستخدام مربع موتر () :
مثال
const tensorA = tf.tensor([1, 2, 3, 4]);
// Tensor Square
const tensorNew = tensorA.square();
// Result [ 1, 4, 9, 16 ]
إعادة تشكيل الموتر
عدد العناصر في الموتر هو نتاج الأحجام في الشكل.
نظرًا لأنه يمكن أن تكون هناك أشكال مختلفة بنفس الحجم ، فمن المفيد غالبًا إعادة تشكيل موتر لأشكال أخرى بنفس الحجم.
يمكنك إعادة تشكيل موتر باستخدام tensor.reshape () :
مثال
const tensorA = tf.tensor([[1, 2], [3, 4]]);
const tensorB = tensorA.reshape([4, 1]);
// Result: [ [1], [2], [3], [4] ]