# coding: utf-8 import numpy as np np.__version__ a = np.zeros((3, 3)) a a = np.ones((3, 3)) a a.shape a.dtype a = np.array([1,2,3]) a a = np.array(range(9)) a a = np.arange(0, 12) a b = a.reshape((3, 4)) b a.dtype a = a.astype(np.float64) a a.dtype b b = b.astype(np.float32) b.dtype a[0] a a[0] a[1:4] a[:4] a[4:] a[:] a a[:] b b[1,0] b[1,0] b[1,:] b[:,1] b[:2, :] b b[1:3, 1:3] b - 4 b * b b**2 np.sum(b) np.min(b) np.max(b) np.mean(b) np.sum(b, axis=1) b np.sum(b, axis=0) a = np.ones((500,500), dtype=np.float32) a def f1(arr): return a + 5 def f1(arr): return arr + 5 def f2(arr): h, w = arr.shape for i in range(h): for j in range(w): arr[i,j] += 5 a get_ipython().magic('time f1(a)') get_ipython().magic('time f2(a)') a b np.pad(b, 2, 'constant', cval=0) np.pad(b, 2, 'constant') x = np.array([1,2,2,3]) x.dot(x) I = np.eye(4) I I.dot(x) import cv2 van = cv2.imread("van.png") van.shape cv2.imwrite("van_out.png", van) van_blue = van[:,:,0] cv2.imwrite("van_blue.png", van_blue) van.dtype van = van.astype(np.float32) / 2555 van.min() van.max() van *= 2555 van /= 255 van.max() van *= 1.2 van_out = (van * 255).clip(0, 255).astype(np.uint8) cv2.imwrite("van_adj.png", van_out)