# 주어진 차원에 맞춰 텐서(Tensor)를 어떻게 합칠 수 있나요?

**URL:** <https://discuss.pytorch.kr/t/tensor/24>\
**Category:** 자주 묻는 질문&답변\
**Created:** [5월 18, 2021, 1:31오후 UTC](https://discuss.pytorch.kr/t/tensor/24 "2021-05-18T13:31:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![9bow](https://discuss.pytorch.kr/user_avatar/discuss.pytorch.kr/9bow/32/16301_2.png) [@9bow](https://discuss.pytorch.kr/u/9bow)\
**Post date:** [5월 18, 2021, 1:31오후 UTC](https://discuss.pytorch.kr/t/tensor/24/1 "2021-05-18T13:31:13Z")

</div>

공식 홈페이지와 [StackOverflow](https://stackoverflow.com/questions/tagged/pytorch) 등에서 자주 보이는 질문과 답변을 번역하고 있습니다.

다음 링크에서 원문을 함께 찾아보실 수 있습니다.

- 원문: [Concatenate torch tensor along given dimension - PyTorch Forums](https://discuss.pytorch.org/t/concatenate-torch-tensor-along-given-dimension/2304)

* * *

## 질문

- Tensorflow에서는 다음과 같이 텐서를 합칠 수 있었습니다.

```python
third_tensor= tf.concat(0, [first_tensor, second_tensor])

```

- 이 때, `first_tensor`와 `second_tensor`의 크기(shape)가 각각 `[5, 32, 32]`일 때,  
첫번째 차원(dimension)은 배치 크기(batch\_size)입니다.  
이렇게 두 개의 텐서를 합친 `third_tensor`의 크기는 `[10, 32, 32]`가 됩니다.
- 파이토치에서는 어떻게 할 수 있나요?

---

<div class="post-metadata">

**Author:** ![9bow](https://discuss.pytorch.kr/user_avatar/discuss.pytorch.kr/9bow/32/16301_2.png) [@9bow](https://discuss.pytorch.kr/u/9bow)\
**Post date:** [4월 23, 2022, 6:29오전 UTC](https://discuss.pytorch.kr/t/tensor/24/2 "2022-04-23T06:29:48Z")

</div>

## 답변

- `torch.cat()`의 [문서](https://pytorch.org/docs/stable/generated/torch.cat.html)를 참고하세요.
- 예를 들어 아래와 같이 할 수 있습니다.

```python
third_tensor = torch.cat((first_tensor, second_tensor), 0)

```

## 더 알아보기

- `torch.cat()` 문서: [torch.cat — PyTorch 2.10 documentation](https://pytorch.org/docs/stable/generated/torch.cat.html) (예제도 포함되어 있습니다.)
