파이썬[Python]: numpy - identity 함수

numpy 모듈 - identity 함수(function)


/// 설명

정방형 배열을 반환합니다.

n: (n x n) = (행 x 열)
dtype: 배열의 데이터 형식을 결정합니다. 기본값은 float 입니다.
like: Numpy 배열이 아닌 형태로 생성하는 것을 허용합니다.(__array_function__ 프로토콜을 사용합니다.)

※ 형식
numpy.identity(n, dtype=None, *, like=None)

reference
https://numpy.org/devdocs/reference/generated/numpy.identity.html

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
 
test_np = np.identity(4)
print(test_np)
# [[1. 0. 0. 0.]
#  [0. 1. 0. 0.]
#  [0. 0. 1. 0.]
#  [0. 0. 0. 1.]]
 
test_np = np.identity(4, dtype=int)
print(test_np)
# [[1 0 0 0]
#  [0 1 0 0]
#  [0 0 1 0]
#  [0 0 0 1]]
 
 
def np_with_comas(object):
    return np.array2string(object, separator=', ')
 
 
test_np = np.identity(2)
print(np_with_comas(test_np))
# [[1., 0.],
#  [0., 1.]]
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수