import tensorflow as tf
import numpy as np
x = [i for i in range(10)]
print(x)
y = tf.reshape(x, shape=[-1, 5])
print(y)
print(y.shape)
# 배열을 reshape을 할 경우, 배열의 원소의 갯수는 [-1, 3]의 경우는 3의 배수의 원소의 갯수를 요구한다.
# 배열을 reshape을 할 경우, 배열의 원소의 갯수는 [-1, 2]의 경우는 2의 배수의 원소의 갯수를 요구한다.
x = np.array([
[
[1,1,1],
[2,2,2]
],
[
[3,3,3],
[4,4,4]
],
])
print(x)
print(x.shape)
y = tf.reshape(x, shape=[-1])
print(y)
print(y.shape)
y = tf.reshape(x, shape=[-1, 3])
print(y)
print(y.shape)
y = tf.reshape(x, shape=[-1, 1, 3])
print(y)
print(y.shape)
import tensorflow as tf
import numpy as np
x = np.array([
[0],[1],[2]
])
print(x)
print(x.shape)
y = tf.squeeze(x)
print(y)
print(y.shape)
x = np.array([
[[1],[2]],
[[3],[4]],
])
print(x)
print(x.shape)
y = tf.squeeze(x)
print(y)
print(y.shape)
import numpy as np
import tensorflow as tf
x = np.array([
0, 1, 2
])
print("x.shape: ", x.shape)
y = tf.expand_dims(x, 0)
print(y)
print("y.shape: ", y.shape)
#(1,3)
y = tf.expand_dims(x, 1)
print(y)
print("y.shape: ", y.shape)
#(3,1)
x = np.array(
[
[1, 2],
[3, 4]
]
)
print("x.shape: ", x.shape)
y = tf.expand_dims(x, 0)
print(y)
print(y.shape)
y = tf.expand_dims(x, 1)
print(y)
print(y.shape)
y = tf.expand_dims(x, 2)
print(y)
print(y.shape)
y = tf.expand_dims(x, -1)
print(y)
print(y.shape)