본문 바로가기

Python

generate a sequence of random int in range import random nums = [x for x in range(10)] random.shuffle(nums) print(nums) 더보기
Random int generation in range from random import randint print(randint(0, 9)) integers ranging from 0 to 9 will be chosen randomly 더보기
How to fit a curve using scipy.optimize.curve >>> import numpy as np >>> import matplotlib.pyplot as plt >>> from scipy.optimize import curve_fit >>> >>> def func(x, a, b, c): ... return a * np.exp(-b * x) + c Define the data to be fit with some noise: >>> >>> xdata = np.linspace(0, 4, 50) >>> y = func(xdata, 2.5, 1.3, 0.5) >>> np.random.seed(1729) >>> y_noise = 0.2 * np.random.normal(size=xdata.size) >>> ydata = y + y_noise >>> plt.plot(xd.. 더보기
Histogram function def _Histogram(data, start_range, end_range, delta, x1, x2, y1, y2): # the histogram of the data bins = [] while (start_range < end_range): bins.append(start_range) start_range = start_range + delta values, bins, patches = plt.hist(data, bins, normed=False) plt.xlabel('Input Data Value') plt.ylabel('Occurrence') plt.grid(True) plt.axis([x1, x2, y1, y2]) plt.show()def _Histogram(data, min_val, ma.. 더보기
Copy files in a directory to another directory from shutil import copy # base-network dir base_net_dir = '/home/dooseop/PycharmProjects/Proj075/TORCS_trained_net/ID0_epoch_5_steer' # create destination folder net_dir = os.path.join(learning_params['net_dir'], run_id) if not tf.gfile.Exists(net_dir): tf.gfile.MakeDirs(net_dir) if (isLane): source = os.listdir(base_net_dir) for files in source: copy(os.path.join(base_net_dir, files), net_dir) 더보기
Get file list in a directory from os import listdir from os.path import isfile, join onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] 더보기
Perspective transform import numpy as np import cv2 import matplotlib.pyplot as plt img = cv2.imread('D:/21_pycharm_project/Proj02/mark4.bmp') rows,cols,ch = img.shape # input potision pts1 = np.float32([[98,21],[187,21],[96,102],[188,102]]) # output position pts2 = np.float32([[128,21],[157,21],[96,102],[188,102]]) # get perspective transform matrix M = cv2.getPerspectiveTransform(pts1,pts2) # warp dst = cv2.warpPer.. 더보기
how to plot a histogram : matplotlib import matplotlib.pyplot as plt# the histogram of the data bins = [] for i in range(-1000, 1001): bins.append(i) values, bins, patches = plt.hist(np.squeeze(np.array(steers)), np.squeeze(np.array(bins)), normed=False) plt.xlabel('Steering Angle (x1000.0)') plt.ylabel('Occurrence') plt.grid(True) plt.axis([-500, 500, 0, 1000]) plt.show() # for CDF plot cdf = [] acc_value = 0 for i in range(0, len.. 더보기
How to resize an image : skimage library ** 파이썬 이미지 크기 변형하기 **In matlab, it is very easy to resize an image. However, in python, you need to know which library do I have to import before resizing. In python, skimage library supports resizing an image like matlab. Here is an example. Enjoy!from skimage.transform import resize import skimage.io as io img = io.imread(file_name) img_resize = resize(img, (target_height, target_width)) 더보기
How to show an image : skimage library In matlab, it is very easy to show an image. However, in python, you need to know which library do I have to import before plotting the graph. In python, skimage library supports showing an image like matlab. Here is an example. Enjoy! import skimage.io as io img = io.imread(file_name) io.imshow(img) io.show() 더보기