https://drive.google.com/uc?id=12XAaMr_EsRpilogp6Z_Cb1h-mpTOJnOE
import tensorflow as tf
import numpy as np
t1 = tf.constant(np.pi)
t2 = tf.constant([1, 2, 3, 4])
t3 = tf.constant([[1, 2], [3, 4]])
r1 = tf.rank(t1)
r2 = tf.rank(t2)
r3 = tf.rank(t3)
s1 = t1.get_shape()
s2 = t2.get_shape()
s3 = t3.get_shape()
print('크기:', s1, s2, s3)
print('랭크:', r1.numpy(), r2.numpy(), r3.numpy())
### 결과
# 크기: () (4,) (2, 2)
# 랭크: 0 1 2
import tensorflow as tf
import numpy as np
arr = np.array([[1., 2., 3., 3.5], [4., 5., 6., 6.5], [7., 8., 9., 9.5]])
T1 = tf.constant(arr)
print(T1)
s = T1.get_shape()
print('T1의 크기:', s)
print('T1의 크기:', T1.shape)
T2 = tf.Variable(np.random.normal(size=s))
print(T2)
T3 = tf.Variable(np.random.normal(size=s[0]))
print(T3)
### 결과
# tf.Tensor(
# [[1. 2. 3. 3.5]
# [4. 5. 6. 6.5]
# [7. 8. 9. 9.5]], shape=(3, 4), dtype=float64)
# T1의 크기: (3, 4)
# T1의 크기: (3, 4)
# <tf.Variable 'Variable:0' shape=(3, 4) dtype=float64, numpy=
# array([[ 1.24591289, 0.42771636, -0.23259698, -0.31242843],
# [-0.51809936, -0.89199958, -0.49494362, 0.55808144],
# [-0.11522273, -0.24953113, -0.20146965, 1.40888624]])>
# <tf.Variable 'Variable:0' shape=(3,) dtype=float64, numpy=array([-0.56337014, 0.80102639, 0.84823994])>