TensorFlow-bedrywighede

  • Voeg by
  • Trek af
  • Vermenigvuldig
  • Verdeel
  • Vierkantig
  • Hervorm

Tensor toevoeging

Jy kan twee tensors byvoeg deur tensorA.add(tensorB) te gebruik :

Voorbeeld

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] ]


Tensor aftrekking

Jy kan twee tensors aftrek deur tensorA.sub(tensorB) te gebruik :

Voorbeeld

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] ]


Tensor Vermenigvuldiging

Jy kan twee tensors vermenigvuldig met behulp van tensorA.mul(tensorB) :

Voorbeeld

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 ]


Tensor-afdeling

Jy kan twee tensors verdeel deur tensorA.div(tensorB) te gebruik :

Voorbeeld

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 ]


Tensor Square

Jy kan 'n tensor vierkantig gebruik deur tensor.square() :

Voorbeeld

const tensorA = tf.tensor([1, 2, 3, 4]);

// Tensor Square
const tensorNew = tensorA.square();

// Result [ 1, 4, 9, 16 ]


Tensor hervorm

Die aantal elemente in 'n tensor is die produk van die groottes in die vorm.

Aangesien daar verskillende vorms met dieselfde grootte kan wees, is dit dikwels nuttig om 'n tensor na ander vorms met dieselfde grootte te hervorm.

Jy kan 'n tensor hervorm met behulp van tensor.reshape() :

Voorbeeld

const tensorA = tf.tensor([[1, 2], [3, 4]]);
const tensorB = tensorA.reshape([4, 1]);

// Result: [ [1], [2], [3], [4] ]