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://stackoverflow.com/questions/38754668/plane-fitting-in-a-3d-point-cloud | |
def PCA(data, correlation = False, sort = True): | |
""" Applies Principal Component Analysis to the data | |
Parameters | |
---------- | |
data: array | |
The array containing the data. The array must have NxM dimensions, where each | |
of the N rows represents a different individual record and each of the M columns |
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://stackoverflow.com/questions/15753701/how-can-i-pass-a-list-as-a-command-line-argument-with-argparse | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-i', '--input',type = str, default = "sample.json") | |
parser.add_argument( "-l","--list", nargs="*", type=int, default=[0,1,2]) | |
args = parser.parse_args() |
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
def read_data_from_file( filename ): | |
with open(filename, 'r') as json_file: | |
data = json.load(json_file) | |
return data |
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://stackoverflow.com/questions/48609781/distance-between-one-point-and-rest-of-the-points-in-an-array/48610147 | |
from scipy.spatial import distance | |
X = [(35.0456, -85.2672)] | |
coords = [(35.1174, -89.9711), | |
(35.9728, -83.9422), | |
(36.1667, -86.7833)] | |
distance.cdist(X, coords, 'euclidean') | |
array([[ 4.70444794, 1.6171966 , 1.88558331]]) |
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 os | |
files = os.listdir() | |
# files is a string list | |
for filename in files: | |
print(filename) | |
# https://askubuntu.com/questions/443830/delete-all-files-whose-filenames-contain-a-particular-string |
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
# plot 3d points | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
fig = plt.figure(figsize=(4,4)) | |
ax = fig.add_subplot(111, projection='3d') | |
# points np array |
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
with open('filename') as f: | |
lines = f.readlines() | |
with open('write','w') as f: | |
f.write('Hello\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
#https://stackoverflow.com/questions/34372480/rotate-point-about-another-point-in-degrees-python | |
import numpy as np | |
def rotate(p, origin=(0, 0), degrees=0): | |
angle = np.deg2rad(degrees) | |
R = np.array([[np.cos(angle), -np.sin(angle)], | |
[np.sin(angle), np.cos(angle)]]) | |
# atleast_2d View inputs as arrays with at least two dimensions. | |
o = np.atleast_2d(origin) |
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
#!/usr/bin/env python3 | |
# https://stackoverflow.com/questions/32892932/create-the-oriented-bounding-box-obb-with-python-and-numpy | |
def oobb(pts): | |
''' | |
given: | |
pts, 2d or 3d | |
return: | |
corners, center of the oobb | |
''' |
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
// A simple quickref for Eigen. Add anything that's missing. | |
// Main author: Keir Mierle | |
#include <Eigen/Dense> | |
Matrix<double, 3, 3> A; // Fixed rows and cols. Same as Matrix3d. | |
Matrix<double, 3, Dynamic> B; // Fixed rows, dynamic cols. | |
Matrix<double, Dynamic, Dynamic> C; // Full dynamic. Same as MatrixXd. | |
Matrix<double, 3, 3, RowMajor> E; // Row major; default is column-major. | |
Matrix3f P, Q, R; // 3x3 float matrix. |
NewerOlder