(3주차) 3월16일
import tensorflow as tf
import numpy as np
tf.config.experimental.list_physical_devices('GPU')
- 대각행렬선언
tf.constant(np.diag([1,2,3]))
- 1만 포함한 텐서를 만들고 싶음
tf.ones([3,4])
tf.reshape(tf.constant([1]*12),(3,4))
- 0만 포함한 텐서를 만들고 싶음
tf.zeros((3,3))
- 배열선언
tf.constant(range(12))
tf.constant(range(2,6)) # 2,3,4,5
tf.constant(range(2,21,3))
tf.linspace(0,1,14)
tf.linspace(-1,20,14)
tf.linspace([0,-1],[1,20],14,axis=0) # axis=0은 생략가능
tf.linspace([0,-1],[1,20],14,axis=1)
- 랜덤
tf.random.normal([3,3])
tf.random.normal([10])
tf.random.uniform([3,3])
np.random.randn(10)
tf.random.randn(10)
- (2,1) concat (2,1) => (2,2)
- 두번쨰축이 1에서 2로 바뀌네? // axis=1
a=tf.constant([[1],[2]])
b=tf.constant([[3],[4]])
tf.concat([a,b],axis=1)
- (2,1) concat (2,1) => (4,1)
- 첫번쨰 축이 바뀜 // axis=0
a=tf.constant([[1],[2]])
b=tf.constant([[3],[4]])
tf.concat([a,b],axis=0)
- (1,2) concat (1,2) => (2,2) `
- 첫번쨰축// axis=0
a=tf.constant([[1,2]])
b=tf.constant([[3,4]])
tf.concat([a,b],axis=0)
- (1,2) concat (1,2) => (1,4) `
- 두번쨰축// axis=1
a=tf.constant([[1,2]])
b=tf.constant([[3,4]])
tf.concat([a,b],axis=1)
- (2,2,3) concat (2,2,3) => (4,2,3)
- 첫번쨰축 // axis=0
a=tf.reshape(tf.constant(range(12)),(2,2,3))
b=-a
a,b
tf.concat([a,b],axis=0)
- (2,2,3) concat (2,2,3) => (2,4,3)
- 두번쨰축 // axis=1
a=tf.reshape(tf.constant(range(12)),(2,2,3))
b=-a
a,b
tf.concat([a,b],axis=1)
- (2,2,3) concat (2,2,3) => (2,2,6)
- 세번쨰축 // axis=2, axis = -1
a=tf.reshape(tf.constant(range(12)),(2,2,3))
b=-a
a,b
tf.concat([a,b],axis=-1)
- (4,) concat (4,) => (8,)
- 첫번쨰 축
a=tf.constant([1,2,3,4])
b=-a
a,b
tf.concat([a,b],axis=0)
- (4,) concat (4,) => (4,2)
a=tf.constant([1,2,3,4])
b=-a
a,b
tf.concat([a,b],axis=1)
- tf.concat은 차원을 증가시키면서 결합해주는것은 아니다.
- (4) stack (4) => (4,2)
- (4,) stack (4,) => (4,2) // 두번째 축이 비어있다고 인식
a=tf.constant([1,2,3,4])
b=-a
a,b
tf.stack([a,b],axis=1)
- (4) stack (4) => (2,4)
- (,4) stack (,4) => (2,4) // 첫번째 축이 비어있다고 인식
a=tf.constant([1,2,3,4])
b=-a
a,b
tf.stack([a,b],axis=0)
- (2,3,4,5) stack (2,3,4,5) => (2,2,3,4,5)
- 첫번째축이 비어있다고 인식
a=tf.reshape(tf.constant(range(2*3*4*5)),(2,3,4,5))
b=-a
tf.stack([a,b],axis=0)
- (2,3,4,5) stack (2,3,4,5) => (2,2,3,4,5)
- 두번째축이 비어있다고 인식
- (2, ,3,4,5) stack (2, ,3,4,5)
- (2,2,3,4,5)
a=tf.reshape(tf.constant(range(2*3*4*5)),(2,3,4,5))
b=-a
tf.stack([a,b],axis=1)
- (2,3,4,5) stack (2,3,4,5) => (2,3,4,5,2)
- 마지막축이 비어있다고 인식
- (2,3,4,5,) stack (2,3,4,5,)
- (2,3,4,5,2)
a=tf.reshape(tf.constant(range(2*3*4*5)),(2,3,4,5))
b=-a
c=-a*2
아래의 코드에서 ??를 어떻게 바꿔야??
tf.stack([a,b],axis=??) ## 숙제