728x90
반응형
Pytorch tensor 내 특정 값과 해당되는 index가 필요할 경우 아래 코드로 확인할 수 있다.
x = torch.Tensor([11, 22, 33, 22])
print((x==22).nonzero(as_tuple=True)[0])
https://stackoverflow.com/questions/47863001/how-pytorch-tensor-get-the-index-of-specific-value
How Pytorch Tensor get the index of specific value
With python lists, we can do: a = [1, 2, 3] assert a.index(2) == 1 How can a pytorch tensor find the .index() directly?
stackoverflow.com
https://normal-engineer.tistory.com/301
[PyTorch] 특정 조건에 맞는 텐서 출력/인덱싱 등
데이터 안에 이상한 값이 없는지는 확인하고 싶을 때가 있다. 데이터가 이상하면 당연히 결과도 이상하기 때문이다. 넘파이의 경우에는 아래와 같이 where함수를 쓰면 인덱스를 리턴한다. print(np.
normal-engineer.tistory.com
728x90
반응형
'사소한 Tip . 오류 해결법' 카테고리의 다른 글
IOError: cannot write mode CMYK as PNG (0) | 2023.03.28 |
---|---|
[Log 저장] 학습 과정에서 로그파일 작성 train.log / tee 명령어 (0) | 2023.03.17 |
한글 자모 분리될 때 (0) | 2023.03.14 |
[vscode] 파일 확장자로 나열 (0) | 2023.03.13 |
[Anaconda] environment copy / 환경 복제하기 (0) | 2023.03.08 |