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

numpy 모듈 - full 함수(function)


/// 설명

주어진 차원과 형식으로 새로운 배열을 생성합니다. 값은 fill_value 로 채워집니다.

shape: 차원 e.g., (3, 3) or 2
fill_value: 채워지는 값(스칼라 혹은 배열)
dtype: 출력할 배열의 형식입니다. np.array(fill_value).dtype
order: 배열메모리에 저장되는 형식으로 C언어 형식(기본값)은 'C', 포트란 형식은 'F'를 사용합니다.
like: Numpy 배열이 아닌 형태로 생성하는 것을 허용합니다.(__array_function__ 프로토콜을 사용합니다.)

※ 형식
numpy.full(shape, fill_value, dtype=None, order='C', *, like=None)

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

/// 예제 array-like

1
2
3
4
5
6
7
8
9
10
11
import numpy as np
 
array = (124)
print(array)  # (1, 2, 4)
 
test_np = np.full((33), array)
print(test_np)
# [[1 2 4]
#  [1 2 4]
#  [1 2 4]]
 
cs

/// 예제 numpy array

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
32
33
34
import numpy as np
 
np_array = [34]
print(np_array)  # [3, 4]
 
test_np = np.full((32), np_array)
print(test_np)
# [[3 4]
#  [3 4]
#  [3 4]]
 
test_np = np.full((22), None)
print(test_np)
# [[None None]
#  [None None]]
 
test_np = np.full((22), 10.5)
print(test_np)
# [[10.5 10.5]
#  [10.5 10.5]]
 
test_np = np.full(51.5, order='F')
print(test_np)
# [1.5 1.5 1.5 1.5 1.5]
 
 
def np_with_comas(object):
    return np.array2string(object, separator=', ')
 
 
test_np = np.full(51.5)
print(np_with_comas(test_np))
# [1.5, 1.5, 1.5, 1.5, 1.5]
 
cs

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


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

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

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

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

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

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