This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
a = np.array([0, 3, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 1, 3, 4]) | |
unique, counts = numpy.unique(a, return_counts=True) | |
print(dict(zip(unique, counts))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/opencv.hpp> | |
using namespace cv; | |
int main() { | |
Mat img = imread("image.jpg"); | |
namedWindow("test", WINDOW_NORMAL); | |
imshow("test", img); | |
waitKey(0); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Since os.listdir returns filenames in an arbitary order, | |
this function is very handy for generating well-ordered filenames list. | |
Credit: https://stackoverflow.com/questions/4813061/non-alphanumeric-list-order-from-os-listdir/48030307#48030307 | |
""" | |
import re | |
def sorted_alphanumeric(data): | |
convert = lambda text: int(text) if text.isdigit() else text.lower() | |
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] | |
return sorted(data, key=alphanum_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://bytebaker.com/2008/11/03/switch-case-statement-in-python/ | |
def switch_(index_): | |
def zero(): | |
print("You typed zero.\n") | |
def sqr(): | |
print("n is a perfect square\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("This will always be shown first\n") | |
def main(): | |
print("Calling first_module's main method\n") | |
if __name__ == '__main__': | |
# the following will be shown only in `first_module.py` | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list1 = [3, 2, 4, 1, 1] | |
list2 = ['three', 'two', 'four', 'one', 'one2'] | |
zipped = zip(list1, list2) # zip two lists | |
sorted_zip = sorted(zipped) # sort | |
sorted_zip_comb = zip(*sorted_zip) # unzip, then zip again | |
print(list(sorted_zip_comb)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
from bitstring import BitArray | |
# `bin()` function explained | |
bin30 = bin(30) | |
print("--> bin30:\n", bin30) | |
print("--> type(bin30):\n", type(bin30)) | |
print("--> int(bin30, 2):\n", int(bin30, 2)) | |
# generate a long list of random binary numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mymodule | |
print(mymodule.__doc__) | |
print(mymodule.f.__doc__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
for img_file in Path('./JPEGImages').iterdir(): | |
with open('train.txt', 'w') as f: | |
print(img_file.resolve(), file=f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import requests | |
from selenium import webdriver | |
from selenium.webdriver import ActionChains | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from bs4 import BeautifulSoup | |
import time |
OlderNewer