scipy.ndimage.median¶
- scipy.ndimage.median(input, labels=None, index=None)[源代码]¶
计算已标记区域上数组的值的中位数。
- 参数
- inputarray_like
值的类似数组。对于由指定的每个区域 labels ,的中位数 input 对该区域进行了计算。
- labelsARRAY_LIKE,可选
一组类似整数的数组,用于标记不同的区域,其中值为 input 是要计算出来的。 labels 必须具有与的形状相同的形状 input 。如果 labels 未指定,则返回整个数组的中位数。
- indexARRAY_LIKE,可选
计算中值时考虑的区域标签列表。如果INDEX为NONE,则为以下所有元素的中位数 labels 是非零的,则返回。
- 退货
- median浮点数或浮点数列表
中位数列表 input 在由以下因素确定的区域范围内 labels 以及谁的索引在 index 。如果 index 或 labels 未指定,则返回浮点数: input 如果 labels 为None,元素的中值为 labels 如果出现以下情况,则大于零 index 是没有的。
注意事项
该函数返回Python列表而不是NumPy数组,请使用 np.array 若要将列表转换为数组,请执行以下操作。
示例
>>> from scipy import ndimage >>> a = np.array([[1, 2, 0, 1], ... [5, 3, 0, 4], ... [0, 0, 0, 7], ... [9, 3, 0, 0]]) >>> labels, labels_nb = ndimage.label(a) >>> labels array([[1, 1, 0, 2], [1, 1, 0, 2], [0, 0, 0, 2], [3, 3, 0, 0]]) >>> ndimage.median(a, labels=labels, index=np.arange(1, labels_nb + 1)) [2.5, 4.0, 6.0] >>> ndimage.median(a) 1.0 >>> ndimage.median(a, labels=labels) 3.0