티스토리 뷰
Tensorflow에서 제공하는 tf.math.argmax함수는 tensor의 가장 큰 값의 index를 return해주는 함수이다.
기본 형태는
tf.math.argmax(input, axis = None, output_type = tf.dtype.int64, name = None)
위와 같다.
input값은 tensor여야 하고, axis는 default는 0이고, max값을 찾을 축을 의미한다.
예제 1)
a = tf.constant([2, 20, 30, 6, 3])
tf.math.argmax(a)
a에서는 30이 가장 큰 값이고, 30의 index는 2 이므로, argmax 함수의 return 값은 2가 된다.
예제 2)
a = tf.constant([[2, 20, 30, 3, 6], [3, 11, 16, 1, 8], [14, 45, 23, 5, 27]])
tf.math.argmax(a)
tf.math.argmax(a)는 tf.math.argmax(a, 0)과 같다(default = 0)
a.shape = (3, 5)이고 axis = 0은 5를 의미하므로,
각각의 array에서 같은 index별로 가장 큰 값을 가진 array의 index를 return한다.
[2, 3, 14], [20, 11, 45], [30, 16, 23], [3, 1, 5], [6, 8, 27] 중 가장 큰 값의 index를 각각 return한다.
return값은 [2, 2, 0, 2, 2] 가 된다.
예제 3)
a = tf.constant([[2, 20, 30, 3, 6], [3, 11, 16, 1, 8], [14, 45, 23, 5, 27]])
tf.math.argmax(a, 1)
a.shape = (3, 5)이고 axis = 1은 3를 의미하므로 axis=1을 parameter로 주게 되면,
각각의 array [2, 20, 30, 3, 6], [3, 11, 16, 1, 8], [14, 45, 23, 5, 27] 에서 가장 큰 값의 index를 각각 return한다.
return값은 [2, 2, 1] 이 된다.
'이것저것 자료 > Python' 카테고리의 다른 글
[python library] matplotlib.pyplot에서 TypeError: Couldn't find foreign struct converter for 'cairo.Context' Error (0) | 2021.08.10 |
---|---|
[python library] opencv 설치하기 (0) | 2021.08.09 |
[python] Tensorflow tf.math.equal 함수 (0) | 2021.08.04 |
[python library] numba install error (0) | 2021.07.27 |
[python module] scipy 설치 (0) | 2021.07.27 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- LGSVL
- 파이썬
- 백트래킹
- 동적프로그래밍
- 설치하기
- 카카오
- PIP
- error
- torchscript
- numpy
- notfound
- docker
- torch
- 다익스트라
- BFS
- 백준
- Python
- version
- 설치
- 이것이코딩테스트다
- 코딩테스트
- matplotlib
- CUDA
- shellscript
- tensorflow
- dfs
- n과m
- 최소신장트리
- pytorch
- 프로그래머스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함