import tensorflow as tf
import numpy as np
t = tf.convert_to_tensor(1)
<tf.Tensor: shape=(), dtype=int32, numpy=0>
t = tf.convert_to_tensor([1, 2])
<tf.Tensor: shape=(), dtype=int32, numpy=1>
<tf.Tensor: shape=(), dtype=int32, numpy=1>
<tf.Tensor: shape=(), dtype=int32, numpy=2>
t = tf.convert_to_tensor(
[
[1, 2],
[3, 4]
]
)
<tf.Tensor: shape=(), dtype=int32, numpy=2>
<tf.Tensor: shape=(), dtype=int32, numpy=2>
<tf.Tensor: shape=(), dtype=int32, numpy=3>
t = tf.convert_to_tensor(
[
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]
)
<tf.Tensor: shape=(), dtype=int32, numpy=3>
<tf.Tensor: shape=(), dtype=int32, numpy=2>
TensorShape([2, 2, 2])
t = tf.convert_to_tensor(
[
[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 12, 12],
],
[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 12, 12],
],
]
)
<tf.Tensor: shape=(), dtype=int32, numpy=3>
TensorShape([2, 3, 4])
<tf.Tensor: shape=(), dtype=int32, numpy=7>
<tf.Tensor: shape=(3,), dtype=int32, numpy=array([ 3, 7, 12], dtype=int32)>
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([7, 7], dtype=int32)>
<tf.Tensor: shape=(4,), dtype=int32, numpy=array([5, 6, 7, 8], dtype=int32)>
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([7, 8], dtype=int32)>
t = tf.convert_to_tensor([1, 2])
<tf.Tensor: shape=(), dtype=int32, numpy=1>
TensorShape([2])
t2 = tf.expand_dims(t, 1)
TensorShape([2, 1])
<tf.Tensor: shape=(), dtype=int32, numpy=2>
<tf.Tensor: shape=(2, 1), dtype=int32, numpy=
array([[1],
[2]], dtype=int32)>
<tf.Tensor: shape=(), dtype=int32, numpy=2>
t3 = tf.expand_dims(t, 0)
<tf.Tensor: shape=(1, 2), dtype=int32, numpy=array([[1, 2]], dtype=int32)>
<tf.Tensor: shape=(), dtype=int32, numpy=2>
<tf.Tensor: shape=(1, 2), dtype=int32, numpy=array([[2, 3]], dtype=int32)>