+-*/?
a = tf.fill([2, 2], 2.)
# print(a)
b = tf.ones([2, 2])
# print(b)
c = a + b
print(c.shape)
d = a - b
print(d.shape)
e = a * b
print(e.shape)
f = a / b
print(f.shape)
res:
(2, 2)
(2, 2)
(2, 2)
(2, 2)
log, exp
b = tf.ones([2, 2])
a = tf.math.log(b)
print(a)
c = tf.exp(b)
print(c)
res:
tf.Tensor(
[[0. 0.]
[0. 0.]], shape=(2, 2), dtype=float32)
tf.Tensor(
[[2.7182817 2.7182817]
[2.7182817 2.7182817]], shape=(2, 2), dtype=float32)
pow, sqrt
a = tf.fill([2, 2], 2.)
b = tf.pow(a, 3)
print(b)
b = a ** 3
print(b)
c = tf.sqrt(a)
print(c)
res:
tf.Tensor(
[[8. 8.]
[8. 8.]], shape=(2, 2), dtype=float32)
tf.Tensor(
[[8. 8.]
[8. 8.]], shape=(2, 2), dtype=float32)
tf.Tensor(
[[1.4142134 1.4142134]
[1.4142134 1.4142134]], shape=(2, 2), dtype=float32)
@matmul:
a = tf.fill([2, 2], 2.)
b = tf.ones([2, 2])
c = a@b
print(c)
d = tf.matmul(a, b)
print(d)
res:
tf.Tensor(
[[4. 4.]
[4. 4.]], shape=(2, 2), dtype=float32)
tf.Tensor(
[[4. 4.]
[4. 4.]], shape=(2, 2), dtype=float32)
a = tf.ones([4, 2, 3])
b = tf.fill([4, 3, 5], 2.)
c = a @ b
print(c)
d = tf.matmul(a, b)
print(d)
res:
tf.Tensor(
[[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]
[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]
[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]
[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]], shape=(4, 2, 5), dtype=float32)
tf.Tensor(
[[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]
[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]
[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]
[[6. 6. 6. 6. 6.]
[6. 6. 6. 6. 6.]]], shape=(4, 2, 5), dtype=float32)
|