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

[numpy] PY - NumPy Array Indexing (배열 색인) ★ - 배열 요소에 접근

2256  
배열 색인 (= 배열 요소에 접근)

 

※ 앞 (= 왼쪽)부터 색인 : 0부터 시작. (예: 0, 1, 2, ....)

※ 뒤 (= 오른쪽)부터 색인 : -1부터 시작. (예: -1, -2, -3, ...)

 


[1차원 배열]

 

import numpy as np

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

print(arr[0]) # 1 (첫 번째요소)

print(arr[1]) # 2 (두 번째요소)

print(arr[2] + arr[3]) # 7 (= 3 + 4)

 


[2차원 배열]

 

import numpy as np

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

print('1번째 차원 2번째 요소: ', arr[0, 1]) # 2

print('2번째 차원 5번째 요소: ', arr[1, 4]) # 10

 


[3차원 배열]

 

import numpy as np

arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])

# 3차원의 1번째 차원, 2차원의 2번째 차원, 1차원의 3번째 값.

print(arr[0, 1, 2]) # 6

 


[음수 색인]

 

import numpy as np

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

print('2번째 차원 마지막 요소: ', arr[1, -1]) # 10

 

 


분류 제목
module Python - math.erf() 메서드 -
module Python - math.erfc() 메서드 -
module Python - math.exp() 메서드 -
module Python - math.expm1() 메서드 -
module Python - math.fabs() 메서드 -
module Python - math.factorial() 메서드 -
module Python - math.floor() 메서드 ★ - 바닥 반올림 (= 하위 정수로 반올림. = floor메…
module Python - math.fmod() 메서드 -
module Python - math.frexp() 메서드 -
module Python - math.fsum() 메서드 -
module Python - math.gamma() 메서드 -
module Python - math.gcd() 메서드 -
module Python - math.hypot() 메서드 -
module Python - math.isclose() 메서드 -
module Python - math.isfinite() 메서드 - 숫자 유한 여부 체크 (= math.isfinite메…
module Python - math.isinf() 메서드 -
module Python - math.isnan() 메서드 ★ - NaN 여부 체크. (= isnan메서드 = 이즈난메서…
module Python - math.isqrt() 메서드 -
module Python - math.ldexp() 메서드 -
module Python - math.lgamma() 메서드 -
20/24
목록
찾아주셔서 감사합니다. Since 2012