3. Tensor Operations
t1=tf.constant([1,2,3]) t2=tf.constant([10,20,30]) print(t1+t2) tf.Tensor([11 22 33], shape=(3,), dtype=int32) tensor의 constant 변수끼리 더하면 결과로 원소들의 합을 출력한다.(Elementwise) py_list1=[1,2,3] py_list2=[10,20,30] print(py_list1+py_list2) [1, 2, 3, 10, 20, 30] 반면 파이썬(numpy)의 리스트 변수끼리 덧셈 연산을 하면 리스트 두개가 concat된다. 원소끼리 합을 하고싶다면 for문을 이용해서 원소 하나하나 직접 덧셈해주어야 한다. print(t1-t2) print(t1*t2) print(t1/t2) print(t1..
2. API를 사용하여 Tensor 만들기
텐서의 크기를 매우 크게 늘리고 싶을 때 shape을 사용하면 손쉽게 할 수 있습니다. t2=tf.ones(shape=(100,)) print(t2) t3=tf.ones(shape=(100,3,3)) print(t3) t4=tf.zeros(shape=(100,3,3)) print(t3) t2와 t3는 1이 채워진 100x1, 100x3x3텐서입니다. t4는 0이 채워진 100x3x3 텐서입니다. 만약 다른 숫자로 텐서를 채우고 싶다면 t5 = 3*tf.ones(shape=(128,128,3)) ones 앞에 원하는 숫자를 곱해주면 됩니다. t5는 3이 채워져 있는 128x128x3 텐서입니다. test_list2=[[1,2,3],[4,5,6]] t1=tf.Variable(test_list2) print(..