Pytorch/Summarize2 1. 텐서(tensor)란?_array와 list를 이용하여 텐서 생성하기 numpy ndarray나 python의 list도 tensor로 바꿀 수 있다. 1. numpy ndarray to tensor 먼저 array 를 생성해보자. x_np = np.array([[1.0, 2.0], [3.0, 4.0]]) 앞서 포스팅한 constant 안에 넣어도 되지만 convert_to_tensor 를 사용할 수도 있다. # tf.constant 이용 x_np_1 = tf.constant(x_np) # convert_to_tensor 이용 x_np_2 = tf.convert_to_tensor(x_np) 두 결과의 데이터타입을 확인해보면 위와 같이 동일한 것을 확인할 수 있다. 2. python list to tensor array 를 단순히 list로 변경만 하면 되므로 코드를 한번에.. 2022. 8. 24. 1. 텐서(tensor)란?_텐서 생성하기 텐서란? Tensor는 multi-dimensional array를 나타내는 말로, TensorFlow의 기본 data type 이다. 텐서를 만들기 위해서는 간단하게 tf.constant 를 이용하여 만들 수 있다. 1.텐서 생성하기_기본형 hello = tf.constant([3,3], dtype=tf.float32) 결과는 넘파이의 array 와는 다르게 숫자와 함께 shape 과 데이터타입을 함께 출력한다. tf.Tensor([3. 3.], shape=(2,), dtype=float32) 글자를 넣어서 만들 수도 있는데 hello = tf.constant('hello world') 이때의 결과는 다음과 같다. tf.Tensor(b'hello world', shape=(), dtype=string).. 2022. 8. 24. 이전 1 다음