Python3を用いたグラフ描写プログラムを書いていきます。
Python 3.6.6
matplotlib
numpy
from sklearn.datasets import load_digits | |
import matplotlib.pyplot as plt | |
data = load_digits() | |
for num, image, label in zip(range(10), data.images[:10], data.target[:10]): | |
plt.subplot(2, 5, num+1) | |
plt.imshow(image) | |
plt.title(label) |
import requests | |
from io import BytesIO | |
from PIL import Image | |
import numpy as np | |
def url_to_image(url): | |
""" | |
url -> np.array (RGB) | |
""" |
from tensorflow.keras.utils import to_categorical | |
def preprocessing(data, ch=3, label=False): | |
if label: | |
return to_categorical(data) | |
data = data / 255.0 | |
w, h = data[0:3] | |
data = data.reshape((-1, w, h, ch)) | |
return data |
from io import BytesIO | |
from PIL import Image | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import cv2 | |
cap = cv2.VideoCapture(0) | |
ret, frame = cap.read() |
import cv2 | |
ESC_KEY = 27 | |
cap = cv2.VideoCapture(0) | |
while True: | |
ret, frame = cap.read() | |
# |
import math | |
def avg_entropy(num_arr): | |
num_arr = list(map(lambda x: x * math.log2(x), num_arr)) | |
return -sum(num_arr) | |
if __name__=='__main__': | |
input_num = [0.05, 0.25, 0.70] | |
output = avg_entropy(input_num) | |
print('output :', output) |