nanmedian#

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

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

Parameters:
  • self – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the means are computed. The default is to compute the mean of the flattened 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. With this option, the result will broadcast correctly against the original a. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.

  • overwrite_input (bool, default: False) – If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and a is not already an ndarray, an error will be raised.

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

Return type:

Array

Returns:

  • ret – A new array holding the result. If the input contains integers

  • This function is *nestable*, and therefore also accepts (code:’ivy.Container’)

  • instance in place of the argument.

Examples

With ivy.Array input:

>>> x = ivy.array([[12.0, 10.0, 34.0], [45.0, 23.0, ivy.nan]])
>>> ivy.nanmedian(x)
    ivy.array(23.)
With a mix of :class:`ivy.Container` and :class:`ivy.Array` input:
>>> x = ivy.Container(a=ivy.array([[10.0, ivy.nan, 4], [3, 2, 1]]),
        b=ivy.array([[12, 10, 34], [45, 23, ivy.nan]]))
>>> ivy.nanmedian(x)
{
    a: ivy.array(3.),
    b: ivy.array(23.)
}
Array.nanmedian(self, /, *, axis=None, keepdims=False, overwrite_input=False, out=None)[source]#

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

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – The axis or axes along which the means are computed. The default is to compute the mean of the flattened 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. With this option, the result will broadcast correctly against the original input array. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.

  • overwrite_input (bool, default: False) – If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and input array is not already an ndarray, an error will be raised.

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

Return type:

Array

Returns:

ret – A new array holding the result. If the input contains integers

Examples

With ivy.array input and default backend set as numpy:

>>> a = ivy.array([[10.0, ivy.nan, 4], [3, 2, 1]])
>>> a.nanmedian()
    ivy.array(3.)
>>> a.nanmedian(axis=0)
    ivy.array([6.5, 2. , 2.5])
Container.nanmedian(self, /, *, axis=None, keepdims=False, overwrite_input=False, out=None)[source]#

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

Parameters:
  • self (Container) – Input array.

  • axis (Optional[Union[int, Tuple[int], Container]], default: None) – The axis or axes along which the means are computed. The default is to compute the mean of the flattened 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. With this option, the result will broadcast correctly against the original container. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.

  • overwrite_input (Union[bool, Container], default: False) – If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array.Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and input container does not already have leaves which are of the ndarray kind, an error will be raised.

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

Return type:

Container

Returns:

ret – A new array holding the result. If the input contains integers

Examples

With ivy.Container input and default backend set as numpy: >>> x = ivy.Container(a=ivy.array([[10.0, ivy.nan, 4], [3, 2, 1]]),

b=ivy.array([[12, 10, 34], [45, 23, ivy.nan]]))

>>> x.nanmedian()
{
    a: ivy.array(3.),
    b: ivy.array(23.)
}
>>> x.nanmedian(axis=0)
{
    a: ivy.array([6.5, 2., 2.5]),
    b: ivy.array([28.5, 16.5, 34.])
}