nlcpy.nanmedian
- nlcpy.nanmedian(a, axis=None, out=None, overwrite_input=False, keepdims=nlcpy._NoValue)
- Computes the median along the specified axis, while ignoring NaNs. - Returns the median of the array elements. - Parameters
- aarray_like
- Input array or object that can be converted to an array. 
- axis{int, sequenceof int, None}, optional
- Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array. 
- outndarray, optional
- Alternative output array in which to place the result. It must have the same shape as the expected output but the type (of the calculated values) will be cast if necessary. 
- overwrite_inputbool, optional
- 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. 
- keepdimsbool, optional
- 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 array. 
 
- Returns
- medianndarray
- A new array holding the result. If the input contains integers or floats smaller than - float64, then the output data-type is- nlcpy.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead.
 
 - See also - Note - Given a vector - Vof length- N, the median of- Vis the middle value of a sorted copy of- V, V_sorted- i.e.,- V_sorted[(N-1)/2], when- Nis odd, and the average of the two middle values of- V_sortedwhen- Nis even.- Restriction - This function is the wrapper function to utilize - numpy.nanmedian(). Calculations during this function perform on only Vector Host(Linux/x86).- Examples - >>> import nlcpy as vp >>> a = vp.array([[10.0, 7, 4], [3, 2, 1]]) >>> a[0, 1] = vp.nan >>> a array([[10., nan, 4.], [ 3., 2., 1.]]) >>> vp.median(a) array(nan) >>> vp.nanmedian(a) array(3.) >>> vp.nanmedian(a, axis=0) array([6.5, 2. , 2.5]) >>> vp.median(a, axis=1) array([nan, 2.]) >>> b = a.copy() >>> vp.nanmedian(b, axis=1, overwrite_input=True) array([7., 2.]) >>> assert not vp.all(a==b) >>> b = a.copy() >>> vp.nanmedian(b, axis=None, overwrite_input=True) array(3.) >>> assert not vp.all(a==b)