Example #1
0
def nanargmax(a, axis=None):
    """ Returns the indices of the maximum values in the specified axis ignoring NaNs.

    For all-NaN slices ``ValueError`` is raised. Warning: the results cannot be trusted
    if a slice contains only NaNs and -Infs.

    Parameters
    ----------
    a : array_like
        Input data.
    axis : int, optional
        Axis along which to operate. By default flattened input is used.

    Returns
    -------
    index_array : ndarray
        An array of indices or a single index value.

    See Also
    --------
    argmax : Returns the indices of the maximum values along an axis.
    nanargmin : Returns the indices of the minimum values in the specified axis
                ignoring NaNs.

    Examples
    --------
    >>> import nlcpy as vp
    >>> a = vp.array([[vp.nan, 4], [2, 3]])
    >>> vp.argmax(a)
    array(0)
    >>> vp.nanargmax(a)
    array(1)
    >>> vp.nanargmax(a, axis=0)
    array([1, 0])
    >>> vp.nanargmax(a, axis=1)
    array([1, 1])
    """
    a = nlcpy.array(a)
    if a.dtype.kind not in 'fc':
        return nlcpy.argmax(a, axis=axis)

    mask = nlcpy.isnan(a)
    if nlcpy.any(nlcpy.all(mask, axis=axis)):
        raise ValueError("All-NaN slice encountered")
    nlcpy.copyto(a, -nlcpy.inf, where=mask)
    return nlcpy.argmax(a, axis=axis)
Example #2
0
def testinge_case_6():
    a = vp.array([[10, 7, 4], [3, 2, 1]])
    b = a.copy()
    vp.quantile(b, 0.5, axis=1, overwrite_input=True)
    return vp.all(a == b)
Example #3
0
def testinge_case_6():
    a = vp.array([[10., 7., 4.], [3., 2., 1.]])
    a[0][1] = vp.nan
    b = a.copy()
    vp.nanpercentile(b, 50, axis=1, overwrite_input=True)
    return vp.all(a == b)
Example #4
0
def test_me_case_2():
    a = nlcpy.array([[10, 7, 4], [3, 2, 1]])
    b = a.copy()
    ny.median(b, axis=None, overwrite_input=True)
    assert not ny.all(a == b)
Example #5
0
def test_me_case_1():
    a = ny.array([[10, 7, 4], [3, 2, 1]])
    b = a.copy()
    ny.median(b, overwrite_input=False)
    print("a={} b={}".format(a, b))
    assert ny.all(a == b)