[API] Tensorflow Control Flow

(텐서플로우 제어 연산자)

Note: Functions taking  Tensor  arguments can also take anything accepted by  tf.convert_to_tensor .


Tensorflow Logical Operators

TensorFlow provides several operations that you can use to add logical operators to your graph.


tf.logical_and(x, y, name=None)


Returns the truth value of x AND y element-wise.

Args:
  • x: A Tensor of type bool.
  • y: A Tensor of type bool.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Logical Operators


Tensorflow tf.logical_and 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.logical_and(tf.cast(const1, tf.bool), tf.cast(const2, tf.bool)))
   ...:     print(str(xs) + " -> " + str(tfutil.get_operation_value(tf.cast(y, tf.int32))))
(0, 0) -> 0
(1, 0) -> 0
(0, 1) -> 0
(1, 1) -> 1


tf.logical_not(x, name=None)


Returns the truth value of NOT x element-wise.

Args:
  • x: A Tensor of type bool.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Logical Operators


Tensorflow tf.logical_not 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [0, 1]:
   ...:     const = tf.constant(xs)
   ...:     y = tfutil.get_operation_value(tf.logical_not(tf.cast(const, tf.bool)))
   ...:     print(str(xs) + " -> " + str(tfutil.get_operation_value(tf.cast(y, tf.int32))))
0 -> 1
1 -> 0

tf.logical_or(x, y, name=None)


Returns the truth value of x OR y element-wise.

Args:
  • x: A Tensor of type bool.
  • y: A Tensor of type bool.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Logical Operators


Tensorflow tf.logical_or 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.logical_or(tf.cast(const1, tf.bool), tf.cast(const2, tf.bool)))
   ...:     print(str(xs) + " -> " + str(tfutil.get_operation_value(tf.cast(y, tf.int32))))
(0, 0) -> 0
(1, 0) -> 1
(0, 1) -> 1
(1, 1) -> 1

tf.logical_xor(x, y, name='LogicalXor')


x ^ y = (x | y) & ~(x & y).


출처: Control Flow > Logical Operators


Tensorflow tf.logical_xor 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.logical_xor(tf.cast(const1, tf.bool), tf.cast(const2, tf.bool)))
   ...:     print(str(xs) + " -> " + str(tfutil.get_operation_value(tf.cast(y, tf.int32))))
(0, 0) -> 0
(1, 0) -> 1
(0, 1) -> 1
(1, 1) -> 0


Tensorflow Comparison Operators

TensorFlow provides several operations that you can use to add comparison operators to your graph.


tf.equal(x, y, name=None)


Returns the truth value of (x == y) element-wise.

Args:
  • x: A Tensor. Must be one of the following types: halffloat32float64uint8int8int16int32int64complex64quint8qint8qint32stringboolcomplex128.
  • y: A Tensor. Must have the same type as x.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Comparison Operators


Tensorflow tf.equal 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (1, 0)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.equal(const1, const2))
   ...:     print(str(xs) + " -> " + str(y))
(0, 0) -> True
(1, 0) -> False

tf.not_equal(x, y, name=None)


Returns the truth value of (x != y) element-wise.

Args:
  • x: A Tensor. Must be one of the following types: halffloat32float64uint8int8int16int32int64complex64quint8qint8qint32stringboolcomplex128.
  • y: A Tensor. Must have the same type as x.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Comparison Operators


Tensorflow tf.not_equal 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (1, 0)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.not_equal(const1, const2))
   ...:     print(str(xs) + " -> " + str(y))
(0, 0) -> False
(1, 0) -> False

tf.less(x, y, name=None) 


Returns the truth value of (x < y) element-wise.


Args:

• x : A  Tensor . Must be one of the following types:  float32 ,  float64 ,  int32 ,  int64 ,  uint8 ,  int16 ,  int8 ,  uint16 ,  half .

• y : A  Tensor . Must have the same type as  x .

• name : A name for the operation (optional).


Returns:


A  Tensor  of type  bool .


출처: Control Flow > Comparison Operators


Tensorflow tf.less 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (0, 1), (1, 0)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.less(const1, const2))
   ...:     print(str(xs[0]) + " < " + str(xs[1]) + " -> " + str(y))
0 < 0 -> False
0 < 1 -> True
1 < 0 -> False

tf.less_equal(x, y, name=None)


Returns the truth value of (x <= y) element-wise.

Args:
  • x: A Tensor. Must be one of the following types: float32float64int32int64uint8int16int8uint16half.
  • y: A Tensor. Must have the same type as x.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Comparison Operators


Tensorflow tf.less_equal 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (0, 1), (1, 0)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.less_equal(const1, const2))
   ...:     print(str(xs[0]) + " <= " + str(xs[1]) + " -> " + str(y))
0 <= 0 -> True
0 <= 1 -> True
1 <= 0 -> False


tf.greater(x, y, name=None)


Returns the truth value of (x > y) element-wise.

Args:
  • x: A Tensor. Must be one of the following types: float32float64int32int64uint8int16int8uint16half.
  • y: A Tensor. Must have the same type as x.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Comparison Operators


Tensorflow tf.greater 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (0, 1), (1, 0)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.greater(const1, const2))
   ...:     print(str(xs[0]) + " > " + str(xs[1]) + " -> " + str(y))
0 > 0 -> False
0 > 1 -> False
1 > 0 -> True


tf.greater_equal(x, y, name=None)


Returns the truth value of (x >= y) element-wise.


Args:
  • x: A Tensor. Must be one of the following types: float32float64int32int64uint8int16int8uint16half.
  • y: A Tensor. Must have the same type as x.
  • name: A name for the operation (optional).
Returns:

Tensor of type bool.


출처: Control Flow > Comparison Operators


Tensorflow tf.greater_equal 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: for xs in [(0, 0), (0, 1), (1, 0)]:
   ...:     const1, const2 = tf.constant(xs[0]), tf.constant(xs[1])
   ...:     y = tfutil.get_operation_value(tf.greater_equal(const1, const2))
   ...:     print(str(xs[0]) + " >= " + str(xs[1]) + " -> " + str(y))
0 >= 0 -> True
0 >= 1 -> False
1 >= 0 -> True



이 포스팅은 머신러닝/딥러닝 오픈소스 Tensorflow 개발을 위한 선행학습으로 Tensorflow API Document의 Python API 대한 학습노트입니다.

Posted by 이성윤

[API] Tensorflow Math

(텐서플로우 수학 함수)


Tensorflow 기본 수학 함수

참조: Tensorflow 수학 함수 API 문서

 

함수

설명

tf.add

덧셈

tf.subtract

뺄셈

tf.multiply

곱셈

tf.div

나눗셈의 몫(Python 2 스타일)

tf.truediv

나눗셈의 몫(Python 3 스타일)

tf.mod

나눗셈의 나머지

tf.abs

절대값을 리턴합니다.

tf.negative

음수를 리턴합니다.

tf.sign

부호를 리턴합니다.(역주음수는 -1, 양수는 1, 0 일땐 0을 리턴합니다)

tf.reciprocal

역수를 리턴합니다.(역주: 3의 역수는 1/3 입니다)

tf.square

제곱을 계산합니다.

tf.round

반올림 값을 리턴합니다.

tf.sqrt

제곱근을 계산합니다.

tf.pow

거듭제곱 값을 계산합니다.

tf.exp

지수 값을 계산합니다.

tf.log

로그 값을 계산합니다.

tf.maximum

최대값을 리턴합니다.

tf.minimum

최소값을 리턴합니다.

tf.cos

코사인 함수 값을 계산합니다.

tf.sin

사인 함수 값을 계산합니다.


Tensorflow Arithmetic Operators 함수 결과

In [1]: import tensorflow as tf

In [2]: import tfutil
In [3]: const1, const2 = tf.constant([1]), tf.constant([2, 3])
In [4]: var1, var2 = tf.Variable([4]), tf.Variable([5, 6])
In [5]: tfutil.print_constant(const1)
[1]
In [6]: tfutil.print_constant(const2)
[2 3]
In [7]: tfutil.print_variable(var1)
[4]
In [8]: tfutil.print_variable(var2)
[5 6]
In [9]: tfutil.print_operation_value(tf.add(const1, var1))
[5]
In [10]: tfutil.print_operation_value(tf.add(const2, var2))
[7 9]
In [11]: tfutil.print_operation_value(tf.subtract(const1, var1))
[-3]
In [12]: tfutil.print_operation_value(tf.subtract(const2, var2))
[-3 -3]
In [13]: tfutil.print_operation_value(tf.multiply(const1, var1))
[4]
In [14]: tfutil.print_operation_value(tf.multiply(const2, var2))
[10 18]
In [15]: tfutil.print_operation_value(tf.div(const1, var1))
[0]
In [16]: tfutil.print_operation_value(tf.div(const2, var2))
[0 0]
In [17]: tfutil.print_operation_value(tf.mod(const1, var1))
[1]
In [18]: tfutil.print_operation_value(tf.mod(const2, var2))
[2 3]
In [19]: tfutil.print_operation_value(tf.square(var1))
[16]
In [20]: tfutil.print_operation_value(tf.square(var2))
[25 36]
In [21]: tfutil.print_operation_value(tf.square(const1))
[1]
In [22]: tfutil.print_operation_value(tf.square(const2))
[4 9]


이 포스팅은 머신러닝/딥러닝 오픈소스 Tensorflow 개발을 위한 선행학습으로 Tensorflow API Document의 Python API 대한 학습노트입니다.

Posted by 이성윤

[Part3. Unit 22] 

패턴 113(~인지 아닌지 알아요? / 혹시 ~에요? [Do you know if]

~ 121(~라는 걸 알려 드리고 싶네요. [I'd like to let you know])



패턴 113 ~인지 아닌지 알아요? / 혹시 ~에요? [Do you know if]

문장에 if가 나오면 두 가지로 추측해 볼 수 있죠. 하나는 '만약에' 라는 가정이고, 다른 하나는 ' ~인지 어떤지'라는 뜻이지요. Do you know와 만난 if는 여기서 두 번째의 의미랍니다.

1. 그 경기 취소 되었는지 어떤지 너 알아?
★ Do you know if the game was canceled?

2. 집에 누가 있는지 알아?
★ Do you know if anyone's home?

3. 네가 그것을 할 수 있을지 알아?
★ Do you know if you'll be able to make it?

4. 표가 아직 남아 있는지 어떤지 너 알아?
★ Do you know if there are still tickets available?

5. 아직 세일 중인지 너 아니?

★ Do you know if the sale is still going on?

패턴 114 ~인지 아닌지 모르겠어요. [I don't know if]

앞에서 알아본 Do you know if...와 같은 패턴이지요. '나는 of다으멩 나오는 내용이 그런지 안 그런지 잘 모르겠다'는 말이랍니다.

1. 내가 이것을 이렇게 많이 가져도 될지 모르겠어.
★ I don't know if I can take much more of this.

2. 그게 가능한지 모르겠어요.
★ I don't know if that's possible.

3. 집주인이 애완 동물을 허락할지 모르겠어요.
★ I don't know if the landlord allows pets.

4. 이 소파를 놓을 장소가 충분한지 모르겠어요.
★ I don't know if we have enough space for this couch.

5. 그 차가 국토 횡단을 할 수 있을지 모르겠네요.

★ I don't know if the car will make it across the country.


패턴 115 내가 ~할 수 있을지 모르겠어요. [I don't now if I can]

앞에서 나온 I don't konw if 다음에 '나는 할 수 있다'는 말인 can이 오는 패턴이죠? 여러 모로 많이 확욜할 수 있으니 더 연습해 보기로 해요.

1. 내가 도와줄 수 있을지 모르겠네.
★ I don't know if I can help you.

2. 제시간에 올 수 있을지 모르겠어요.
★ I don't know if I can make it on time.

3. 그렇게 많은 시간을 쉴 수 있을지 모르겠어요.
★ I don't know if I can take that much time off of work.

4. 그렇게 많은 책임을 질 수 있을지 모르겠어요.
★ I don't know if I can handle that much responsibility.

5. 이것을 이렇게 많이 가져도 될지 모르겠네요.

★ I don't know if I can take much more of this.


패턴 116 어떻게(얼마나) ~하는지 아세요? [Do you know how]

how는 방법을 나타내지요. 그래서 이 패턴은 무엇을 어떻게 하는지 물어볼 때 쓸 수 있답니다. 앞의 Do you know가 의문문 형태로 되어 있기 떄문에 how다음에 오는 문장은 '주어+동사'가 된다는 것 잊지 마세요.

1. 그곳까지 가는 데 얼마나 걸리는지 아세요?
★ Do you know how long it takes to get there?

2. 이 문제 어떻게 풀어야 하는지 아세요?
★ Do you know how to solve this problem?

3. 어떻게 이 일이 일어났는지 아세요?
★ Do you know how this happened?

4. 이게 어떻게 작동되는지 아시나요?
★ Do you know how this works?

5. 제 기분이 어떤지 아세요?

★ Do you know how I feel?


패턴 117 왜 ~한지 아세요? [Do you know why]

why는 '이유'나 '까닭'의 답을 요구하는 '왜?"라는 뜻이죠? 친구와 대화를 나눌 때 한 번 이상 쓸 수 있을 것이니 꼭 기억하세요.

1. 왜 가게 문을 닫았는지 아세요?
★ Do you know why they closed the store?

2. 그녀가 왜 일찍 갔는지 알아?
★ Do you know why she left early?

3. 그 사람이 왜 집을 팔았는지 아세요? 
★ Do you know why he sold his house?

4. 왜 그 사람이 갈 수 없는지 아세요?
★ Do you know why he can't go?

5. 넌 왜 그 사람들이 콘서트를 취소했는지 알아? 

★ Do you know why they canceled the concert?


패턴 118 ~를 아세요? [Do you know what]

여기서 what은 의문사로 쓰여 '무엇/무슨'이란 뜻을 나타내기도 하고, 관계사로 쓰여 '~하는 것'이란 뜻을 나타내기도 해요. 어떤 경우이든 Do you know...가 있기 때문에 이 패턴은 물어보는 말이 되지요.

1. 제 말이 무슨 뜻인지 아시겠어요?
★ Do you know what I mean?

2. 지금 몇 신지 아세요?
★ Do you know what time it is?

3. 제가 무슨 생각을 하고 있는지 아시나요?
★ Do you know what I think?

4. 그녀가 무슨 말을 했는지 아세요?
★ Do you know what she said?

5. 무슨 일이 일어났는지 아세요?

★ Do you know what happened?


패턴 119 언제 ~하는지 알아요? [Do you know when]

when은 '시간'에 관한 의문사죠? 그러므로 이 패턴은 언제 문을 닫는지, 언제 영화가 시작되는지 등 시간을 물어볼 때 쓰세요.

1. 언제 도서관을 여는지 아세요?
★ Do you know when the library opens?

2. 공연이 언제 시작되는지 알아?
★ Do you know when the show starts?

3. 그들이 언제 저녁을 주는지 알아?
★ Do you know when they'll be serving dinner?

4. 비행기가 언제 출발하는지 아세요?
★ Do you know when the plane leaves?

5. 언제 제 차례가 되는지 아세요?

★ Do you know when I can have a turn?


패턴 120 내가 ~를 어떻게 알아요? [How do I know]

친구에게 퉁명스럽게 말을 할 때 쓸 수 있는 패턴으로, 약간은 의기소침과 짜증스러운 눈빛으로 말해야 실감이 나죠. 안 그런 경우도 있지만 대부분 그렇다는 말씀이에요.

1. 그게 언제 끝나는지 내가 어떻게 알아요?
★ How do I know when it's done?

2. 네가 진실을 말하는지 내가 어떻게 알아?
★ How do I know that you're telling the truth?

3. 이게 괜찮은 거래인지 제가 어떻게 압니까?
★ How do I know if this is a good deal?

4. 이게 잘 된 결정인지 제가 어떻게 알아요?
★ How do I know if this is the right decision?

5. 그 사람이 성실한 사람인지 내가 어떻게 알아요?

★ How do I know if he's being sincere?


패턴 121 ~라는 걸 알려 드리고 싶네요. [I'd like to let you know]

let you know를 직역하면 '네가 알도록 만들겠다'란 말이 되므로 이것은 '내가 너에게 어떤 정보를 주겠다'는 뜻이 되지요.

1. 내가 내린 결정을 알려 주마.
★ I'd like to let you know what I've decided.

2. 내 계획을 알려 줄게.
★ I'd like to let you know about my plans.

3. 무엇이 기대되는지 가르쳐 줄게.
★ I'd like to let you know what to expect.

4. 제 공부 결과를 알려 드리고 싶네요.
★ I'd like to let you know the results of my study.

5. 당신에게 감사하다는 것을 알려 드리고 싶어요.

★ I'd like to let you know that you're appreciated.


이 포스팅은 영어회화 핵심패턴 233 교재의 Unit 22(패턴 113 ~ 패턴 121)대한 학습노트입니다.

Posted by 이성윤