標量時間是一個張量
在以下示例中,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.]]