How can a function that operates on 2D arrays (cdist) be applied along an axis of a 3D array ?
I tried with numpy.apply_along_axis
, but I need to operate on 2D arrays, not 1D. I obtained the result I need by iterating along one axis, but I would prefer it vectorized if possible:
from scipy import spatial
import numpy as np
a = np.random.randn(600).reshape(10, 20, 3)
distances = np.array([spatial.distance.cdist(a[i,:,:], a[i,:,:]) for i in range(a.shape[0])])