본문 바로가기
Python

Numpy.transpose

by 코딩하는 미토콘드리아 bioinformatics 2022. 1. 10.
반응형

np.transpose 함수를 통해서

행렬의 행과 열의 위치를

교환 할 수 있다.

 

예를들어,

2 X 2 행렬의 A가 있는 경우

A 행렬의 1행 2열의 값을 2행 1열의 값으로,

2행 1열의 값을 1행 2열의 값으로

교환하는 것이다.

이렇게 교환된 행렬은

전치 행렬 이라고 하고

A.T 로 표기한다.

 

 

A = np.array([[1,2],
[3,4]])
transpose_mat = np.transpose(A)
print('A의 전치 행렬:\n', transpose_mat)

[output]

A의 전치 행렬:
[[1 3]
[2 4]]

 

 

Reference

1.https://numpy.org/doc/stable/reference/generated/numpy.transpose.html

 

numpy.transpose — NumPy v1.22 Manual

If specified, it must be a tuple or list which contains a permutation of [0,1,..,N-1] where N is the number of axes of a. The i’th axis of the returned array will correspond to the axis numbered axes[i] of the input. If not specified, defaults to range(a

numpy.org

2. 파이썬 머신러닝 완벽가이드 위키북스 데이터 사이언스 시리즈

반응형

'Python' 카테고리의 다른 글

for 나 while 루프 뒤에 else 블록을 사용하지 말자  (0) 2022.01.18
range 보다는 enumerate 를 사용하자  (0) 2022.01.17
Numpy.dot  (0) 2022.01.10
Numpy.sort, argsort  (0) 2022.01.09
Numpy Fancy Indexing, Boolean Indexing  (0) 2022.01.06