Exemplo n.º 1
0
def setmember1d(ar1, ar2):
    """
    Return a boolean array set True where first element is in second array.

    See Also
    --------
    numpy.setmember1d : equivalent function for ndarrays.

    """
    ar1 = ma.asanyarray(ar1)
    ar2 = ma.asanyarray(ar2)
    ar = ma.concatenate((ar1, ar2))
    b1 = ma.zeros(ar1.shape, dtype=np.int8)
    b2 = ma.ones(ar2.shape, dtype=np.int8)
    tt = ma.concatenate((b1, b2))

    # We need this to be a stable sort, so always use 'mergesort' here. The
    # values from the first array should always come before the values from the
    # second array.
    perm = ar.argsort(kind="mergesort")
    aux = ar[perm]
    aux2 = tt[perm]
    #    flag = ediff1d( aux, 1 ) == 0
    flag = ma.concatenate((aux[1:] == aux[:-1], [False]))
    ii = ma.where(flag * aux2)[0]
    aux = perm[ii + 1]
    perm[ii + 1] = perm[ii]
    perm[ii] = aux
    #
    indx = perm.argsort(kind="mergesort")[: len(ar1)]
    #
    return flag[indx]
Exemplo n.º 2
0
def setmember1d(ar1, ar2):
    """ This function is deprecated. Use ma.in1d() instead."""
    ar1 = ma.asanyarray(ar1)
    ar2 = ma.asanyarray( ar2 )
    ar = ma.concatenate((ar1, ar2 ))
    b1 = ma.zeros(ar1.shape, dtype = np.int8)
    b2 = ma.ones(ar2.shape, dtype = np.int8)
    tt = ma.concatenate((b1, b2))

    # We need this to be a stable sort, so always use 'mergesort' here. The
    # values from the first array should always come before the values from the
    # second array.
    perm = ar.argsort(kind='mergesort')
    aux = ar[perm]
    aux2 = tt[perm]
#    flag = ediff1d( aux, 1 ) == 0
    flag = ma.concatenate((aux[1:] == aux[:-1], [False]))
    ii = ma.where( flag * aux2 )[0]
    aux = perm[ii+1]
    perm[ii+1] = perm[ii]
    perm[ii] = aux
    #
    indx = perm.argsort(kind='mergesort')[:len( ar1 )]
    #
    return flag[indx]
Exemplo n.º 3
0
def setmember1d(ar1, ar2):
    """
    Return a boolean array set True where first element is in second array.

    See Also
    --------
    numpy.setmember1d : equivalent function for ndarrays.

    """
    ar1 = ma.asanyarray(ar1)
    ar2 = ma.asanyarray( ar2 )
    ar = ma.concatenate((ar1, ar2 ))
    b1 = ma.zeros(ar1.shape, dtype = np.int8)
    b2 = ma.ones(ar2.shape, dtype = np.int8)
    tt = ma.concatenate((b1, b2))

    # We need this to be a stable sort, so always use 'mergesort' here. The
    # values from the first array should always come before the values from the
    # second array.
    perm = ar.argsort(kind='mergesort')
    aux = ar[perm]
    aux2 = tt[perm]
#    flag = ediff1d( aux, 1 ) == 0
    flag = ma.concatenate((aux[1:] == aux[:-1], [False]))
    ii = ma.where( flag * aux2 )[0]
    aux = perm[ii+1]
    perm[ii+1] = perm[ii]
    perm[ii] = aux
    #
    indx = perm.argsort(kind='mergesort')[:len( ar1 )]
    #
    return flag[indx]
Exemplo n.º 4
0
def setmember1d(ar1, ar2):
    """ This function is deprecated. Use ma.in1d() instead."""
    ar1 = ma.asanyarray(ar1)
    ar2 = ma.asanyarray(ar2)
    ar = ma.concatenate((ar1, ar2))
    b1 = ma.zeros(ar1.shape, dtype=np.int8)
    b2 = ma.ones(ar2.shape, dtype=np.int8)
    tt = ma.concatenate((b1, b2))

    # We need this to be a stable sort, so always use 'mergesort' here. The
    # values from the first array should always come before the values from the
    # second array.
    perm = ar.argsort(kind='mergesort')
    aux = ar[perm]
    aux2 = tt[perm]
    #    flag = ediff1d( aux, 1 ) == 0
    flag = ma.concatenate((aux[1:] == aux[:-1], [False]))
    ii = ma.where(flag * aux2)[0]
    aux = perm[ii + 1]
    perm[ii + 1] = perm[ii]
    perm[ii] = aux
    #
    indx = perm.argsort(kind='mergesort')[:len(ar1)]
    #
    return flag[indx]