[Tensor]#9 indexing with None

Clay Ryu's sound lab·2023년 8월 12일
0

Framework

목록 보기
22/49

The slicing with [None, ...] part adds a new axis (dimension) in place of None. It works for both np.array and tensor in the same way. I prefer to use unsqueeze in tensor for adding axis, but there is no unsqueeze method in numpy.

print(words_np.shape)
# (1407, 7)

words_np[-1][None, ...]
# array([[0, 0, 0, 0, 0, 0, 0]])

words_tensor[-1].unsqueeze(0)
# tensor([[0, 0, 0, 0, 0, 0, 0]])
profile
chords & code // harmony with structure

1개의 댓글

comment-user-thumbnail
2023년 8월 12일

잘 봤습니다. 좋은 글 감사합니다.

답글 달기