To perform elementwise multiplication on tensors, you can use either of the following:
a*b
tf.multiply(a, b)
Here is a full example of elementwise multiplication using both methods.
import tensorflow as tf
import numpy as np
# Build a graph
graph = tf.Graph()
with graph.as_default():
...
In the following example a 2 by 3 tensor is multiplied by a scalar value (2).
# Build a graph
graph = tf.Graph()
with graph.as_default():
# A 2x3 matrix
a = tf.constant(np.array([[ 1, 2, 3],
[10,20,30]]),
dtype=tf.float32)
...
The dot product between two tensors can be performed using:
tf.matmul(a, b)
A full example is given below:
# Build a graph
graph = tf.Graph()
with graph.as_default():
# A 2x3 matrix
a = tf.constant(np.array([[1, 2, 3],
[2, 4, 6]]),
...