tensorflow Matrix and Vector Arithmetic Scalar Times a Tensor

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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)
                    
    # Scalar times Matrix
    c =  2 * a

# Run a Session
with tf.Session(graph=graph) as session:
    output = session.run(c)
    print(output)

This prints out

[[  2.   4.   6.]
 [ 20.  40.  60.]]


Got any tensorflow Question?