아이공의 AI 공부 도전기

 

torch tensor에서 새로운 축을 만들고자 할 때 사용할 수 있는 방법

 

1. torch.unsqueeze (input, dim)

 

ex) torch.unsqueeze(input, dim=0)

 

https://pytorch.org/docs/stable/generated/torch.unsqueeze.html

 

torch.unsqueeze — PyTorch 2.1 documentation

Shortcuts

pytorch.org

 

2. input[:, None]

 

numpy 에서도 비슷하게 사용가능

 

input[None, :]

input[:, None]

input[:, None, None]

 

https://stackoverflow.com/questions/37867354/in-numpy-what-does-selection-by-none-do

 

In numpy, what does selection by [:,None] do?

I'm taking the Udacity course on deep learning and I came across the following code: def reformat(dataset, labels): dataset = dataset.reshape((-1, image_size * image_size)).astype(np.float32) ...

stackoverflow.com

 

etc)

numpy에서는 다음 방법들로 축을 늘릴 수 있다.

 

np.expand_dims(input, axis)

input[:, np.newaxis]

input.reshape()

 

다른 접근법

np.tile()

np.stack()

 

 

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading