Skip to content

Instantly share code, notes, and snippets.

@danlurie
Created May 3, 2020 01:31
Show Gist options
  • Save danlurie/35a2a15f56396bce988c413a04eaf86b to your computer and use it in GitHub Desktop.
Save danlurie/35a2a15f56396bce988c413a04eaf86b to your computer and use it in GitHub Desktop.
unit = [1,0,-1]
Mi = np.empty((27,6), dtype='float')
M_orig = np.flip(np.array(list(itertools.product(unit, repeat=3))), axis=1).astype('float')
M = M_orig.copy()
for row_idx, row_vector in enumerate(M_orig):
row_sum = np.sum(abs(row_vector))
if row_sum == 2:
M[row_idx] = row_vector * (1 / np.sqrt(2))
elif row_sum == 3:
M[row_idx] = row_vector * (1 / np.sqrt(3))
Mi[row_idx] = [M[row_idx,0]**2, # x^2
2*M[row_idx,0]*M[row_idx,1], # 2xy
2*M[row_idx,0]*M[row_idx,2], # 2xz
M[row_idx,1]**2, # y^2
2*M[row_idx,1]*M[row_idx,2], # 2yz
M[row_idx,2]**2] # z^2
Mi = np.delete(Mi, 13, axis=0)
M_orig = np.delete(M_orig, 13, axis=0)
T = np.linalg.inv(Mi.T @ Mi) @ Mi.T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment