from jellyfish import jaro_distance
words = 'CHEESE CHORES GEESE GLOVES'.split()
def d(coord):
i, j = coord
return (1 - jaro_distance(words[i], words[j]))
import numpy as np
a=np.triu_indices(len(words), 1)
np.apply_along_axis(d, axis=0, arr=a)
最后一行np.apply_along_axis给出了以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-59-5af45815fc52> in <module>()
----> 1 np.apply_along_axis(d, axis=-1, arr=a)
/Users/ravinderbhatia/anaconda/lib/python2.7/site-packages/numpy/lib/shape_base.pyc in apply_along_axis(func1d, axis, arr, *args, **kwargs)
130 except StopIteration:
131 raise ValueError('Cannot apply_along_axis when any iteration dimensions are 0')
--> 132 res = asanyarray(func1d(inarr_view[ind0], *args, **kwargs))
133
134 # build a buffer for storing evaluations of func1d.
<ipython-input-50-0f89f3df3d2e> in d(coord)
1 def d(coord):
----> 2 i, j = coord
3 return (1 - jaro_distance(words[i], words[j]))
ValueError: too many values to unpack
无法理解原因。在示例中它似乎运行。