파이썬[Python]: numpy - ones 함수
numpy 모듈 - ones 함수(function)
/// 설명
주어진 배열을 1 로 초기화 합니다.
shape: (n x n) = (행 x 열)
dtype: 출력할 배열의 형식입니다.(기본값은 numpy.float64 입니다.)
order: 배열메모리에 저장되는 형식으로 C언어 형식(기본값)은 'C', 포트란 형식은 'F'를 사용합니다.
like: Numpy 배열이 아닌 형태로 생성하는 것을 허용합니다.(__array_function__ 프로토콜을 사용합니다.)
※ 형식
numpy.ones(shape, dtype=None, order='C', *, like=None)
reference
https://numpy.org/devdocs/reference/generated/numpy.ones.html
shape: (n x n) = (행 x 열)
dtype: 출력할 배열의 형식입니다.(기본값은 numpy.float64 입니다.)
order: 배열메모리에 저장되는 형식으로 C언어 형식(기본값)은 'C', 포트란 형식은 'F'를 사용합니다.
like: Numpy 배열이 아닌 형태로 생성하는 것을 허용합니다.(__array_function__ 프로토콜을 사용합니다.)
※ 형식
numpy.ones(shape, dtype=None, order='C', *, like=None)
reference
https://numpy.org/devdocs/reference/generated/numpy.ones.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 27 28 29 30 31 | import numpy as np test_np = np.ones(4) print(test_np) # [1. 1. 1. 1.] test_np = np.ones((2, 2)) print(test_np) # [[1. 1.] # [1. 1.]] test_np = np.ones(5, dtype=int) print(test_np) # [1 1 1 1 1] test_np = np.ones((3, 3), order='F') print(test_np) # [[1. 1. 1.] # [1. 1. 1.] # [1. 1. 1.]] def np_with_comas(object): return np.array2string(object, separator=', ') test_np = np.ones((2, 2)) print(np_with_comas(test_np)) # [[1., 1.], # [1., 1.]] | cs |
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기