Python_DS2 - jjin-choi/study_note GitHub Wiki

Numpy

  • numpy λŠ” np.array ν•¨μˆ˜λ₯Ό ν™œμš©ν•˜μ—¬ λ°°μ—΄ 생성함 (ndarray)

  • ν•˜λ‚˜μ˜ 데이터 type 만 배열에 넣을 수 있음

  • List 와 κ°€μž₯ 큰 차이점은 Dynamic typing not supported

  • array shape (vector : ex) (4,)) or (matrix : ex) (4,3))

    • μƒˆλ‘œμš΄ 차원이 μƒκΈΈλ•Œλ§ˆλ‹€ μ•žμœΌλ‘œ λ“€μ–΄κ°€κ³  맨 처음 생긴 dimension 이 λ’€λ‘œ 계속 λ°€λ¦°λ‹€.
  • array size λŠ” μ›μ†Œμ˜ 개수 / ndim : λͺ‡ 차원인지

  • array dtype : ndarray 의 single element κ°€ κ°€μ§€λŠ” data type 이며 각 element κ°€ μ°¨μ§€ν•˜λŠ” mem 크기 κ²°μ •

  • .reshpae(-1, 2) : column 이 μ£Όμ–΄μ‘Œμ„ λ•Œ size 에 λ§žλŠ” row 개수λ₯Ό 선정해라

  • .flatten()

  • list 와 달리 [0][0] 도 κ°€λŠ₯ν•˜κ³  [0,0] 도 ν‘œκΈ° κ°€λŠ₯ν•˜λ‹€.

matplotlib

  • pyplot 객체λ₯Ό μ‚¬μš©ν•˜μ—¬ 데이터 ν‘œμ‹œ
  • κ·Έλž˜ν”„λŠ” figure (도화지) 객체에 μƒμ„±λœλ‹€.
  • plt.plot() 을 ν• λ•Œλ§ˆλ‹€ μ μΈ΅λ˜λŠ” ꡬ쑰
import matplotlib.pyplot as plt
  • figure 큰 그림판 μ•ˆμ— axes 둜 ꡬ성 (λ”°λ‘œ μ •μ˜λ₯Ό μ•ˆν•΄μ£Όλ©΄ κ·Έλƒ₯ default 에 κ·Έλ €μ£ΌλŠ” 것)
fig = plt.figure()
fig.set_size_inches(10,5)
ax1 = fig.add_subplot(1,2,1) # 1번째 쀄에 2개 쀑 1 번 μ§Έ 

plt.legend(...)
plt.xlabel('')
plt.ylabel('')
plt.xticks('') # X 의 눈금 
plt.text() 
plt.annotate('line2', ...)

plt.xlim () # limitation
  • bar chart μ—μ„œλŠ” 잘 μ•ˆμ“°μ§€λ§Œ μ„Έλ‘œλ‘œ μŒ“μ•„ 올릴 λ•Œμ—λŠ” bottom μ΄λΌλŠ” κ±Έ 지정해주면 됨
bottom = np.sum(data[:i], axis=0)