np.squeeze, np.expand_dims(unsqueeze) 이해
쓸모없는 차원 1을 제거(squeeze) 또는 추가(expand_dims)expand_dim의 경우, pytorch의 unsqueeze와 같다.예시 sample_array = np.array([[1,2,3], [4,5,6]])# axis를 기준으로 차원 추가sample_array_expand_0 = np.expand_dims(sample_array, axis=0)sample_array_expand_1 = np.expand_dims(sample_array, axis=1)sample_array_expand_2 = np.expand_dims(sample_array, axis=2)# axis를 기준으로 차원 제거(차원이 1인경우만 제거 가능)sample_array_expand_1_squeeze = np.sque..
2025. 3. 30.
np.repeat 이해
배열의 요소를 반복새로운 차원이 생기는 것이 아님import numpy as npnp.repeat(array, repeat_information, axis=None)# array : 반복할 배열# repeat_information : 반복할 횟수(정수 혹은 정수의 배열 가능)# axis : 해당 축을 기준으로 반복(default는 None이며, 해당 경우 평탄화 된 상태에서 반복) 예제sample_array = np.array([[1,2,3], [4,5,6]])# sample_array내의 요소를 4번씩 반복sample_array_repeat_None = np.repeat(sample_array, 4, axis=None)sample_array_repeat_0 = np.repeat(sample_array,..
2025. 3. 30.