furas

Python - mumpy apply_along_axis

Jun 5th, 2018
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. data_1 = np.array([[1], [2]])
  4. data_2 = np.array([[8], [9]])
  5.  
  6. for row1 in data_1:
  7.     f = lambda row2: np.linalg.norm(row2-row1)
  8.     distances = np.apply_along_axis(f, 1, data_2)
  9.     print(distances.min())
RAW Paste Data