[딥러닝 기초]
딥러닝을 하기 위한 텐서플로 기초 사용법입니다. 파이썬 numpy array를 활용해 기본적인 텐서를 생성하고, 생성된 텐서의 정보를 확인해보자.
Tensor의 생성
파이썬 numpy를 통해 생성한 배열/튜플/리스트는 텐서플로의 tf.constant() 함수를 통해 텐서로 변환할 수 있다.
1 | arr = np.array([1, 2, 3]) |
Tensor 정보 확인
tensor.shape: tensor의 shape 확인tensor.dtype: tensor의 데이터 타입 확인텐서 생성시에 데이터 타입을 정의해줄 수 있다.
1
tensor = tf.constant([1, 2, 3], dtype=tf.float32)
tf.cast(): data type 변환- numpy array는
numpy.astype()을 사용해 데이터 타입 변환한다.
1
tf.cast(tensor, dtype=tf.uint8)
- numpy array는
tensor.numpy(),np.array(tensor),type(tensor.numpy()): 텐서에서 numpy불러오기
난수 생성하기
numpy.random.rand(),tf.random.normal(): normal distribution의 난수 생성tf.random.uniform(): uniform distribution의 난수 생성
![[딥러닝 기초]](/image/Elegant_Background-1.jpg)