import tensorflow as tf
import numpy as np
a = tf.constant([1, 5], dtype=tf.int64)
print("a:", a)
print("a.dtype:", a.dtype)
print("a.shape:", a.shape)
a: tf.Tensor([1 5], shape=(2,), dtype=int64)
a.dtype: <dtype: 'int64'>
a.shape: (2,)
a = np.arange(0, 5)
b = tf.convert_to_tensor(a, dtype=tf.int64)
print("a:", a)
print("b:", b)
a: [0 1 2 3 4]
b: tf.Tensor([0 1 2 3 4], shape=(5,), dtype=int64)
a = tf.zeros([2, 3])
b = tf.ones(4)
c = tf.fill([2, 2], 9)
print("a:", a)
print("b:", b)
print("c:", c)
a: tf.Tensor(
[[0. 0. 0.]
[0. 0. 0.]], shape=(2, 3), dtype=float32)
b: tf.Tensor([1. 1. 1. 1.], shape=(4,), dtype=float32)
c: tf.Tensor(
[[9 9]
[9 9]], shape=(2, 2), dtype=int32)
d = tf.random.normal([2, 2], mean=0.5, stddev=1)
print("d:", d)
e = tf.random.truncated_normal([2, 2], mean=0.5, stddev=1)
print("e:", e)
d: tf.Tensor(
[[ 2.5829678 -1.2323483 ]
[-0.6496475 0.18799412]], shape=(2, 2), dtype=float32)
e: tf.Tensor(
[[0.8986387 2.126217 ]
[1.2121066 0.28844398]], shape=(2, 2), dtype=float32)
f = tf.random.uniform([2, 2], minval=0, maxval=1)
print("f:", f)
f: tf.Tensor(
[[0.06484163 0.00596273]
[0.8598033 0.8169972 ]], shape=(2, 2), dtype=float32)