• 회원가입
  • 로그인
  • 구글아이디로 로그인

[numpy] PY - NumPy Array Shape (배열 모양) ★

3763  

목차

  1. 배열 모양 정의
  2. 배열 모양 확인

 

배열 모양 정의

 

배열 차원의 각 차원의 요소 개수로 구성된 Tuple.

 

 

배열 모양 확인

 

NumPy 배열 객체의 shape 속성으로 배열모양 확인 가능. 

※ 각 차원의 요소 개수를 요소로 갖는 Tuple 반환.

※ Tuple의 각 정수는 각 차원의 요소 개수 의미.

※ 2차원 이상의 복잡한 배열 구조 확인에 유용.

 


[0차원 배열]

 

import numpy as np

arr = np.array(34)

print(arr.shape) # ()

 

결과값: ()


[1차원 배열]

 

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr.shape)

 

결과값: (5, )

※ 5 : 1차원 요소 개수 


[2차원 배열] ★

 

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])

print(arr.shape) # (2, 3)

 

결과값: (2, 3)

※ 2 : 1차원 요소 개수

※ 3 : 2차원 각 차원의 요소 개수.


[3차원 배열]

 

import numpy as np

arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])

print(arr.shape)

 

결과값: (2, 2, 3)

※ 2 : 1차원 요소 개수.

※ 2 : 2차원 각 차원의 요소 개수.

※ 3 : 3차원 각 차원의 요소 개수. 


[5차원 배열]

 

import numpy as np

arr = np.array([1, 2, 3, 4], ndmin=5)

print(arr) # [[[[[1 2 3 4]]]]]

print(arr.shape) # (1, 1, 1, 1, 4) 

 

결과값: (1, 1, 1, 1, 4) 

※ 1 : 1차원 요소 개수

※ 1 : 2차원 각 차원의 요소 개수

※ 1 : 3차원 각 차원의 요소 개수

※ 1 : 4차원 각 차원의 요소 개수

※ 4 : 5차원 각 차원의 요소 개수



분류 제목
module Python - cmath 모듈 메서드・상수 종류 (※ 복소수 모듈)
module Python - cmath.acos(x) 메서드 -
module Python - cmath.acosh(x) 메서드 -
module Python - cmath.asin(x) 메서드 -
module Python - cmath.asinh(x) 메서드 -
module Python - cmath.atan(x) 메서드 -
module Python - cmath.atanh(x) 메서드 -
module Python - cmath.cos(x) 메서드 -
module Python - cmath.cosh(x) 메서드 -
module Python - cmath.exp(x) 메서드 -
module Python - cmath.isclose() 메서드 -
module Python - cmath.isfinite(x) 메서드 -
module Python - cmath.isinf(x) 메서드 -
module Python - cmath.isnan(x) 메서드 -
module Python - cmath.log() 메서드 -
module Python - cmath.log10() 메서드 -
module Python - cmath.phase() 메서드 -
module Python - cmath.polar() 메서드 -
module Python - cmath.rect() 메서드 -
module Python - cmath.sin(x) 메서드 -
22/24
목록
찾아주셔서 감사합니다. Since 2012