median#

ivy.median(input, /, *, axis=None, keepdims=False, out=None)[source]#

Compute the median along the specified axis.

Parameters:
  • input (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – The median of the array elements.

Examples

>>> a = ivy.array([[10, 7, 4], [3, 2, 1]])
>>> ivy.median(a)
3.5
>>> ivy.median(a, axis=0)
ivy.array([6.5, 4.5, 2.5])
Array.median(self, /, *, axis=None, keepdims=False, out=None)[source]#

ivy.Array instance method variant of ivy.median. This method simply wraps the function, and so the docstring for ivy.median also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – The median of the array elements.

Examples

>>> a = ivy.array([[10, 7, 4], [3, 2, 1]])
>>> a.median()
3.5
>>> a.median(axis=0)
ivy.array([6.5, 4.5, 2.5])
Container.median(self, /, *, axis=None, keepdims=False, out=None)[source]#

ivy.Container instance method variant of ivy.median. This method simply wraps the function, and so the docstring for ivy.median also applies to this method with minimal changes.

Parameters:
  • self (Container) – Input container including arrays.

  • axis (Optional[Union[int, Tuple[int], Container]], default: None) – Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array.

  • keepdims (Union[bool, Container], default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

  • out (Optional[Container], default: None) – optional output array, for writing the result to.

Return type:

Container

Returns:

ret – The median of the array elements.

Examples

With one ivy.Container input: >>> x = ivy.Container( >>> a=ivy.array([[10, 7, 4], [3, 2, 1]]), >>> b=ivy.array([[1, 4, 2], [8, 7, 0]]) >>> ) >>> x.median(axis=0) {

a: ivy.array([6.5, 4.5, 2.5]), b: ivy.array([4.5, 5.5, 1.])

}