
tf.argmax() / tf.argmin()
: Tensor 내 특정 축(axis)를 기준으로 각각 최대값/최소값의 인덱스들을 찾아 Tensor로 반환한다.
tf.argmax(
input,
axis=None,
output_type=tf.dtypes.int64,
name=None
)
| Args | |
| input | A Tensor |
| axis | An integer, the axis to reduce across. Default to 0. |
| output_type | An optional output dytpe (tf.int 32 or int64) Default to tf.int64 |
| name | An optional name for the operation. |
| Returns | A Tensor of type output_type |
예제
# 배열 생성
A = tf.constant([2, 7, 13, 3, 35])
tf.math.argmax(A).numpy()
>> 4
# 배열 생성
B = tf.constant([[2, 20, 30, 3, 6],
[3, 11, 16, 1, 8],
[14, 45, 23, 5, 27]])
# axis=0(행 기준)
tf.math.argmax(B, 0).numpy()
>>> array([2, 2, 0, 2, 2])
# axis=1(열 기준)
tf.math.argmax(B, 1).numpy()
>>> array([2, 2, 1])
'📘 Programming > Python' 카테고리의 다른 글
| 디렉토리 · 파일 구조 출력 (2) | 2025.07.10 |
|---|