Last active
February 12, 2019 21:49
Euclidean code for medium broadcasting
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 | |
from sklearn.datasets import load_iris | |
Load data: | |
data, _ = load_iris(return_X_y=True) | |
def euc_matrix(A): | |
# generate distance matrix: | |
B = np.rot90(A[:,:,None],1,(1,2)) #[:,:,None] is needed to add a dimension | |
C = np.rot90(B,1,(0,1)) | |
return np.sqrt(np.sum((B-C)**2, axis=2)) | |
mat = euc_matrix(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment