This file contains hidden or 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
def compareDicts(d1, d2): | |
differences = [] | |
# present in d1 but not in d2 | |
for key, value in ({k: d1[k] for k in set(d1) - set(d2)}).iteritems(): | |
temp = list[[key, value], None] | |
differences.append(temp) | |
# present in d2 but not in d1 | |
diff2 = {k: d2[k] for k in set(d2) - set(d1)} |
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using System.Xml; | |
// The indentation settings in the Gist do not seem to be listening to me. size: 4, mode: tabs, (w)rap: Atlanta hip hop |
This file contains hidden or 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
>>> chooseFrom | |
{'1': 10.3438090737, '3': 7.73275047259, '2': 12.9046550095, '5': 10.3438090737, '4': 12.9046550095, '7': 7.88437303088, '6': 5.12169187146, '8': 0.0} | |
>>> gh | |
7.73275047259 | |
# reference : http://stackoverflow.com/a/12141207/799593 | |
>>> test = sorted(chooseFrom, key=lambda x:abs(chooseFrom[x]-gh)) | |
>>> test | |
['3', '7', '1', '5', '6', '2', '4', '8'] |
This file contains hidden or 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
>>> a=[2, 3, 4, 5, 6, 7, 8] | |
>>> b=[4, 2, 3, 8, 1, 5, 7, 6] | |
>>> sorted(a, key = lambda x: b.index(x)) | |
[4, 2, 3, 8, 5, 7, 6] | |
>>> a=[2, 3, 4, 5, 6, 7, 8, 9] | |
>>> sorted(a, key = lambda x: b.index(x)) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 1, in <lambda> | |
ValueError: 9 is not in list |
This file contains hidden or 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 itertools | |
a = [7, 3] | |
b = [3, 1, 2] | |
c = [4, 3, 5] | |
def allEqual(t): | |
same = True | |
This file contains hidden or 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 itertools import izip | |
from PIL import Image | |
import numpy as np | |
def getImageDifference(x, y): | |
diff3 = 1.0 | |
# http://rosettacode.org/wiki/Percentage_difference_between_images#Python | |
if x.size == y.size: | |
pairs = izip(x.getdata(), y.getdata()) |
This file contains hidden or 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
<link href="~/Content/kendo/kendo.common.min.css" rel="stylesheet" /> | |
<link href="~/Content/kendo/kendo.default.min.css" rel="stylesheet" /> | |
<script src="~/Scripts/KendoUI/jquery.min.js"></script> | |
<script src="~/Scripts/KendoUI/kendo.core.min.js"></script> | |
<script src="~/Scripts/KendoUI/kendo.ui.core.min.js"></script> |
This file contains hidden or 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
string str = "Tom Cruise, Scott, ,Bob | at"; | |
IEnumerable<string> names = str | |
.Split(new char[]{',', '|'}) | |
.Where(x=>x!=null && x.Trim().Length > 0) | |
.Select(x=>x.Trim()); |
This file contains hidden or 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
""" About: | |
img is an OpenCV 2 object. img.shape prints a tuple as (height, width, channels) e.g. (512, 768, 3) | |
We need a tuple as (width, height) e.g. (768, 512) | |
""" | |
import cv2 | |
image_path = './image.jpg' | |
img = cv2.imread(image_path, flags=cv2.CV_LOAD_IMAGE_COLOR) | |
print img.shape # (512, 768, 3) | |
print img.shape[::-1] # (3, 768, 512) |
This file contains hidden or 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 | |
x = np.arange(20).reshape(4,5) | |
y = x % 3 == 0 | |
y = y.astype(int) # optional, if dealing with only 1s and 0s | |
# simple | |
np.count_nonzero(y == 1) # 7 | |
np.count_nonzero(y == 0) # 13 | |
(y == 1).sum() # 7 | |
(y == 0).sum() # 13 |
OlderNewer