numpy.apply_along_axis
1、api
numpy.
apply_along_axis
(func1d, axis, arr, *args, **kwargs)
2、参数和返回值
参数:
fun1d | 处理沿axis轴的arr数据,接收一维的数据 |
axis | 按那个轴处理 |
arr | 要处理的数据 |
返回值:
处理后的array型数据,比arr少了一个维度(就是axis制定的维度)
3、实例
>>> a = np.array([[1,2],
... [3,4],
... [5,6]])
>>> a
array([[1, 2],
[3, 4],
[5, 6]])>>> b = np.array([[1,2]])
>>> b.shape
(1, 2)>>> np.apply_along_axis(func1d = np.linalg.norm,axis=1,arr=a-b)
array([0. , 2.82842712, 5.65685425])