Exemplo n.º 1
0
def argsort(objects, axis=-1, output=None):
    """argsort() returns the sort order for 'objects' sorted
    along 'axis'.

    >>> a = ObjectArray(shape=(5,5))
    >>> a[:] = ['e','d','c','b','a']
    >>> argsort(a)
    array([[4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0]])
    """
    if output is None:
        output0 = _nc.zeros(objects._shape)
    else:
        output0 = output
    if axis != -1:
        objects.swapaxes(-1, axis)
        output0.swapaxes(-1, axis)
    _argsort(objects, output0)
    if axis != -1:
        objects.swapaxes(-1, axis)
        output0.swapaxes(-1, axis)
    if output is None:
        return output0
Exemplo n.º 2
0
def argsort(objects, axis=-1, output=None):
    """argsort() returns the sort order for 'objects' sorted
    along 'axis'.

    >>> a = ObjectArray(shape=(5,5))
    >>> a[:] = ['e','d','c','b','a']
    >>> argsort(a)
    array([[4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0],
           [4, 3, 2, 1, 0]])
    """
    if output is None:
        output0 = _nc.zeros(objects._shape)
    else:
        output0 = output
    if axis != -1:
        objects.swapaxes(-1, axis)
        output0.swapaxes(-1, axis)
    _argsort(objects, output0)
    if axis != -1:
        objects.swapaxes(-1, axis)
        output0.swapaxes(-1, axis)
    if output is None:
        return output0
Exemplo n.º 3
0
def _numeric_compress(arr):
    nonzero = 0
    for i in xrange(arr.nelements()):
        if arr[i] != 0: nonzero += 1
    retarr = _nc.zeros((nonzero,))
    nonzero = 0
    for i in xrange(arr.nelements()):
        if arr[i] != 0:
            retarr[nonzero] = abs(arr[i])
            nonzero += 1
    return retarr
Exemplo n.º 4
0
def _numeric_compress(arr):
    nonzero = 0
    for i in xrange(arr.nelements()):
        if arr[i] != 0: nonzero += 1
    retarr = _nc.zeros((nonzero, ))
    nonzero = 0
    for i in xrange(arr.nelements()):
        if arr[i] != 0:
            retarr[nonzero] = abs(arr[i])
            nonzero += 1
    return retarr