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
class ReadOnlyDict(dict): | |
def __setitem__(self, key, value): | |
raise RuntimeError("Modification not supported") | |
rw_dict = {'key': 'original'} | |
print('Dict: ' + str(rw_dict)) | |
ro_dict = ReadOnlyDict(rw_dict) | |
print('ReadOnlyDict: ' + str(ro_dict)) |
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 cyclic_intersection_pts(pts): | |
""" | |
Sorts 4 points in clockwise direction with the first point been closest to 0,0 | |
Assumption: | |
There are exactly 4 points in the input and | |
from a rectangle which is not very distorted | |
""" | |
if pts.shape[0] != 4: | |
return None |
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 yfinance as yf | |
data = yf.download('TSLA', start='2021-02-21', end='2021-02-27', interval='1m') | |
data = data.iloc[:, 0:1] | |
data.to_csv('in/tsla-7day-1min.csv') | |
data = yf.download('TSLA', start='2021-02-01', end='2021-02-27', interval='30m') | |
data = data.iloc[:, 0:1] | |
data.to_csv('in/tsla-1month-30min.csv') |
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
> python redact.py -h | |
usage: redact.py [-h] -i INPUT -o OUTPUT -p PATTERNS [-r REPLACE] [-c COLOR] | |
optional arguments: | |
-h, --help show this help message and exit | |
-i INPUT, --input INPUT | |
Path to the document to be redacted | |
-o OUTPUT, --output OUTPUT | |
Path to save the redacted document | |
-p PATTERNS, --patterns PATTERNS |
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
# Load the Pandas libraries with alias 'pd' | |
import pandas as pd | |
# Read csv to dataframe | |
df = pd.read_csv("data.csv") | |
# Set column types | |
df['Submission Date'] = pd.to_datetime(df['Submission Date'], format="%Y-%m-%d %H:%M") | |
print(df) |
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
""" | |
Script contains functions to process the lines in polar coordinate system | |
returned by the HoughLines function in OpenCV | |
Line equation from polar to cartesian coordinates | |
x = rho * cos(theta) | |
y = rho * sin(theta) | |
x, y are at a distance of rho from 0,0 at an angle of theta |
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
clc; clear all; close all; | |
% Data Generation | |
x = 0:10:2000; | |
y = sigmf(x,[0.1 1000]); | |
n = rand(1,201)/40 - 0.0125; | |
f = y;% + n; | |
fig = figure; | |
set(fig, 'PaperUnits', 'inches'); | |
set(fig, 'PaperPosition', [0 0 8 2]); |
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 | |
def kmeans(data, numofclasses, options=None): | |
""" | |
Calculates the clusters using k-means algorithm and returns cluster labels and centroids | |
:param data: Data to cluster structured as [Number of observations x Data dimensions(variables)] | |
:param numofclasses: Number of classes you want to cluster the data into. | |
:param options: Optional data in dictionary form to overwrite the defaults | |
max_iterations - int: Maximum number of iterations |
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
imageExt = '.png'; | |
imagefiles = dir(['*' imageExt]); | |
outfilename = 'gifname.gif'; | |
for n = 1:length(imagefiles) | |
im = imread(imagefiles(n).name); | |
[imind,cm] = rgb2ind(im,256); | |
% DelayTime in seconds | |
if n == 1 | |
imwrite(imind,cm,outfilename,'gif','Loopcount',inf,'DelayTime',0.7); |
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
#include "fastcv.h" | |
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include <iostream> | |
using namespace cv; | |
using namespace std; | |
int main() | |
{ |
NewerOlder