tf.gather
728x90

tf.gather
내가 원하는 방법으로 tensor 순서를 변경하기 위해 사용하기 용이함

 

tf.gather(
    params, indices, validate_indices=None, axis=None, batch_dims=0, name=None
)

공식 문서가 이해가 안되서 GPT 예시 독촉한 1인

 

# 예시 스펙트럼(2차원 텐서)
spectra = tf.constant([
    [10, 11, 12],  # spectra[0]
    [20, 21, 22],  # spectra[1]
    [30, 31, 32],  # spectra[2]
    [40, 41, 42],  # spectra[3]
])  # shape=(4,3)

# 우리가 뒤섞고 싶은 순서를 인덱스로 적어 놓은 것
mix_indices = tf.constant([1, 2, 3, 0])  # shape=(4,)

tf.gather(spectra, mix_indices)

 

=> 결과
[
  spectra[1],  # [20, 21, 22]
  spectra[2],  # [30, 31, 32]
  spectra[3],  # [40, 41, 42]
  spectra[0],  # [10, 11, 12]
]

 

내가 섞고 싶은 대로 순서를 섞는 텐서를 만드는 함수인듯요ㅎㅎ

나머지 파라미터는 안써봤어요 공식 문서 가서 보셈요 >_<//

 

https://www.tensorflow.org/api_docs/python/tf/gather

 

tf.gather  |  TensorFlow v2.16.1

Gather slices from params axis axis according to indices. (deprecated arguments)

www.tensorflow.org

 

728x90

댓글

공지사항
업데이트
인기 글
«   2025/10   »
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
최근댓글
250x250