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

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

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

 

※ 앞 (= 왼쪽)부터 색인 : 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 - 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