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

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

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

 

※ 앞 (= 왼쪽)부터 색인 : 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 - statistics.mode() 메서드 ★ - 최빈값 반환. (= mode메서드 = 모드)
module Python - statistics.pstdev() 메서드 -
module Python - statistics.stdev() 메서드 -
module Python - statistics.pvariance() 메서드 -
module Python - statistics.variance() 메서드 -
module Python - math 모듈 메서드・상수 종류 (※ 수학 모듈)
module Python - math.acos() 메서드 -
module Python - math.acosh() 메서드 -
module Python - math.asin() 메서드 -
module Python - math.asinh() 메서드 -
module Python - math.atan() 메서드 -
module Python - math.atan2() 메서드 -
module Python - math.atanh() 메서드 -
module Python - math.ceil() 메서드 ★ - 천장 반올림 (= 상위 정수로 반올림. = ceil메서드…
module Python - math.comb() 메서드 -
module Python - math.copysign() 메서드 -
module Python - math.cos() 메서드 -
module Python - math.cosh() 메서드 -
module Python - math.degrees() 메서드 -
module Python - math.dist() 메서드 -
19/24
목록
찾아주셔서 감사합니다. Since 2012