标量时间是一个张量

在以下示例中,2 乘 3 张量乘以标量值(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)

打印出来

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