일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- list
- Python
- math
- Tkinter
- Redshift
- c#
- GIT
- Kotlin
- google apps script
- array
- Google Spreadsheet
- PostgreSQL
- PANDAS
- string
- Apache
- dataframe
- Mac
- Github
- Excel
- matplotlib
- SQL
- Java
- Google Excel
- numpy
- PySpark
- hive
- 파이썬
- django
- gas
- Today
- Total
목록Python (384)
달나라 노트

Python numpy library에는 난수(랜덤한 숫자)를 생성하는 method들이 있는데 어떤 것들이 있고 어떻게 사용할 수 있는지 알아봅시다. - numpy.random.rand() rand method는 0 이상 1 미만의 랜덤한 실수를 생성합니다. import numpy as np test_value = np.random.rand() print(test_value) -- Result 0.11999006968888681 import numpy as np test_value = np.random.rand(3) print(test_value) -- Result [0.56929945 0.43654139 0.87778867] 위 예시처럼 rand method에 숫자를 넣어주면 넣은 숫자의 길이만큼 랜덤..

matplotlib는 굉장히 재미있는 기능들을 제공하는데 그 중에선 image 파일을 읽어서 그래프로 나타내주는 기능을 제공합니다. 제가 이전에 먹었던 녹차빙수 사진을 한번 matplotlib를 이용해서 그래프 위에 나타내보겠습니다. import matplotlib.pyplot as plt import matplotlib.image as img img_test = img.imread('greentea_ice_flakes.png') plt.imshow(img_test) plt.show() directory 구조는 위와 같습니다. pyplot.py 파일에 위 예시코드가 적혀있으며 greentea_ice_flakes.png 파일이 바로 제가 먹었던 녹차빙수 사진입니다. - img_test = img.imrea..

matplotlib에는 imshow라는 method가 있는데 이 method는 array의 값들을 색으로 환산해 이미지의 형태로 보여줍니다. import numpy as np import matplotlib.pyplot as plt arr_test = np.array( [ # 1차 array [0, 1, 0], # 2차 array [1, 0, 1], [0, 1, 0], ] ) plt.imshow(arr_test) plt.show() 위 예시는 2차원 array를 imshow에 적용한 것입니다. 그 결과는 다음과 같습니다. 체스판 형태의 이미지가 나왔죠. 지금부터 왜 위처럼 된건지 알아봅시다. 일단 사용된 array를 보면 2차원이며 다음과 같습니다. [[0 1 0] [1 0 1] [0 1 0]] imsh..

matplotlib에서 그래프를 그리는 방법은 아래 링크를 참고하면 됩니다. https://cosmosproject.tistory.com/341 이번에는 그린 그래프를 이미지 파일로 생성해볼건데 savefig method를 사용할 것입니다. import matplotlib.pyplot as plt list_x_values = [1, 2, 3, 4, 5] list_y_values = [10, 30, 15, 20, 5] plt.figure(linewidth=5) plt.plot(list_x_values, list_y_values, color='skyblue', marker='o', markerfacecolor='blue', markersize=12) plt.title('Test graph') plt.xlab..