Beispiel #1
0
def test_take():
    a = [4, 3, 5, 7, 6, 8]
    indices = [0, 1, 4]
    iassert(afnumpy.take(a, indices), numpy.take(a, indices))
    b = numpy.array(a)
    a = afnumpy.array(a)
    iassert(afnumpy.take(a, indices), numpy.take(b, indices))
Beispiel #2
0
def percentile(a, q, axis=None, out=None,
               overwrite_input=False, interpolation='linear', keepdims=False):
    if interpolation is not 'linear':
        raise ValueError('Only linear interpolation is supported')
    if out is not None:
        raise ValueError('"out" parameter is not supported')
    if isinstance(axis, collections.Sequence):
        raise ValueError('axis sequences not supported')
        
    if axis is None:
        input = a.flatten()
        axis = 0
    else: 
        input = a
    s = afnumpy.sort(input,axis=axis)
    low_idx = numpy.floor(q*(s.shape[axis]-1)/100.0)
    high_idx = numpy.ceil(q*(s.shape[axis]-1)/100.0)
    u = (q*(s.shape[axis]-1)/100.0) - low_idx
    low = afnumpy.take(s, low_idx, axis=axis)
    high = afnumpy.take(s, high_idx, axis=axis)
    ret = u*high+(1-u)*low
    if keepdims is True:
        ret.reshape(ret.shape[:axis]+(1,)+ret.shape[axis:])
    return ret
    
        
Beispiel #3
0
def test_take():
    a = [4, 3, 5, 7, 6, 8]
    indices = [0, 1, 4]
    iassert(afnumpy.take(a, indices), numpy.take(a, indices))
    b = numpy.array(a)
    a = afnumpy.array(a)
    iassert(afnumpy.take(a, indices), numpy.take(b, indices))
Beispiel #4
0
def ifftshift(x, axes=None):
    tmp = afnumpy.asarray(x)
    ndim = len(tmp.shape)
    if axes is None:
        axes = list(range(ndim))
    elif isinstance(axes, numbers.Integral):
        axes = (axes,)
    y = tmp
    for k in axes:
        n = tmp.shape[k]
        p2 = n-(n+1)//2
        mylist = afnumpy.concatenate((afnumpy.arange(p2, n), afnumpy.arange(p2)))
        y = afnumpy.take(y, mylist, k)
    return y
Beispiel #5
0
def percentile(a, q, axis=None, out=None,
               overwrite_input=False, interpolation='linear', keepdims=False):
    if interpolation is not 'linear':
        raise ValueError('Only linear interpolation is supported')
    if out is not None:
        raise ValueError('"out" parameter is not supported')
    if isinstance(axis, collections.Sequence):
        raise ValueError('axis sequences not supported')
        
    if axis is None:
        input = a.flatten()
        axis = 0
    else: 
        input = a
    s = afnumpy.sort(input,axis=axis)
    low_idx = numpy.floor(q*(s.shape[axis]-1)/100.0)
    high_idx = numpy.ceil(q*(s.shape[axis]-1)/100.0)
    u = (q*(s.shape[axis]-1)/100.0) - low_idx
    low = afnumpy.take(s, low_idx, axis=axis)
    high = afnumpy.take(s, high_idx, axis=axis)
    ret = u*high+(1-u)*low
    if keepdims is True:
        ret.reshape(ret.shape[:axis]+(1,)+ret.shape[axis:])
    return ret