np.diag
import numpy as np
sourceList = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
sourceNDArray = np.array(sourceList)
targetNDArray = np.diag(sourceNDArray)
print(targetNDArray)
[결과]
[1 5 9]
출처: https://icodebroker.tistory.com/5277
'대학원 공부 > programming language' 카테고리의 다른 글
Python : __str__ vs __repr__ 차이점 (0) | 2020.02.24 |
---|---|
Python : *args **kwargs (0) | 2020.02.21 |
Numpy : np.reshape, flatten, ravel, newaxis (차원 변경) (0) | 2020.02.21 |
Python : decorater @ (0) | 2020.02.20 |
Pandas : DataFrame vs Series (0) | 2020.02.04 |
댓글