Exemplo n.º 1
0
def crossings(y, value, x=None):
    '''Finds the crossing points where a (poly-)line defined by a 1D y array has the given
    values and return the (linearly) interpolated index or x value if an x array is given 
    '''
    if x is None:
        return _dsutils.crossings(y, value)
    return _dsutils.crossings(x, y, value)
Exemplo n.º 2
0
def crossings(y, value, x=None):
    '''Finds the crossing points where a (poly-)line defined by a 1D y array has the given
    values and return the (linearly) interpolated index or x value if an x array is given 
    '''
    if x is None:
        return _dsutils.crossings(y, value)
    return _dsutils.crossings(x, y, value)
Exemplo n.º 3
0
def normalise(a, allelements=True):
    '''Normalise array so all elements lie between 0 and 1
    Keyword argument:
    allelements -- if True, then normalise for all elements rather than per-element
    '''
    if isinstance(a, _compoundds):
        return _dsutils.norm(a, allelements)
    return _dsutils.norm(a)
Exemplo n.º 4
0
def normalise(a, allelements=True):
    '''Normalise array so all elements lie between 0 and 1
    Keyword argument:
    allelements -- if True, then normalise for all elements rather than per-element
    '''
    if isinstance(a, _compoundds):
        return _dsutils.norm(a, allelements)
    return _dsutils.norm(a)
Exemplo n.º 5
0
def centroid(weights, coords=None):
    '''Calculate the centroid of an array with its (half) indexes or
    coordinates (list of 1D arrays), if given, and returns it as a list
    '''
    if coords is None:
        return _dsutils.centroid(weights)
    from jycore import toList
    return _dsutils.centroid(weights, toList(coords))
Exemplo n.º 6
0
def centroid(weights, coords=None):
    '''Calculate the centroid of an array with its (half) indexes or
    coordinates (list of 1D arrays), if given, and returns it as a list
    '''
    if coords is None:
        return _dsutils.centroid(weights)
    from jycore import toList
    return _dsutils.centroid(weights, toList(coords))
Exemplo n.º 7
0
 def put(self, indices, values):
     if isinstance(indices, ndarray):
         inds = indices._jdataset()
     else:
         inds = asIterable(indices)
     if isinstance(values, ndarray):
         vals = values._jdataset()
     else:
         vals = asIterable(values)
     _dsutils.put(self.__dataset, inds, vals)
Exemplo n.º 8
0
 def put(self, indices, values):
     if isinstance(indices, ndarray):
         inds = indices._jdataset()
     else:
         inds = asIterable(indices)
     if isinstance(values, ndarray):
         vals = values._jdataset()
     else:
         vals = asIterable(values)
     _dsutils.put(self.__dataset, inds, vals)
Exemplo n.º 9
0
def append(arr, values, axis=None):
    '''Append values to end of array
    Keyword argument:
    axis -- if None, then append flattened values to flattened array 
    '''
    if not isinstance(values, _ds):
        values = __cvt_jobj(values, dtype=None, copy=False, force=True)
    if axis is None:
        return _dsutils.append(arr.flatten(), values.flatten(), 0)
    return _dsutils.append(arr, values, axis)
Exemplo n.º 10
0
def append(arr, values, axis=None):
    '''Append values to end of array
    Keyword argument:
    axis -- if None, then append flattened values to flattened array 
    '''
    if not isinstance(values, _ds):
        values = __cvt_jobj(values, dtype=None, copy=False, force=True)
    if axis is None:
        return _dsutils.append(arr.flatten(), values.flatten(), 0)
    return _dsutils.append(arr, values, axis)
Exemplo n.º 11
0
def unravel_index(indices, dims):
    '''Converts a flat index (or array of them) into a tuple of coordinate arrays
    '''
    if isinstance(indices, (tuple, list)):
        indices = ndarray(buffer=indices)._jdataset()
    if not isinstance(indices, _ds):
        return tuple(_abstractds.getNDPositionFromShape(indices, dims))
    return tuple(_dsutils.calcPositionsFromIndexes(indices, dims))
Exemplo n.º 12
0
def where(condition, x=None, y=None):
    '''Return items from x or y depending on condition'''
    if x and y:
        return _dsutils.select(condition, (x, y), 0)
    elif not x and not y:
        return _cmps.nonZero(condition)
    else:
        raise ValueError, "Both x and y must be specified"
Exemplo n.º 13
0
def unravel_index(indices, dims):
    '''Converts a flat index (or array of them) into a tuple of coordinate arrays
    '''
    if isinstance(indices, (tuple, list)):
        indices = ndarray(buffer=indices)._jdataset()
    if not isinstance(indices, _ds):
        return tuple(_abstractds.getNDPositionFromShape(indices, dims))
    return tuple(_dsutils.calcPositionsFromIndexes(indices, dims))
Exemplo n.º 14
0
def where(condition, x=None, y=None):
    '''Return items from x or y depending on condition'''
    if x and y:
        return _dsutils.select(condition, x, y)
    elif not x and not y:
        return _cmps.nonZero(condition)
    else:
        raise ValueError, "Both x and y must be specified"
Exemplo n.º 15
0
def logspace(start, stop, num=50, endpoint=True, base=10.0):
    '''Create a 1D dataset of values equally spaced on a logarithmic scale'''
    if not endpoint:
        stop = ((num - 1) * stop + start) / num

    if complex(start).imag == 0 and complex(stop).imag == 0:
        dtype = _getdtypefromobj(((start, stop)))
        return _dsutils.logSpace(start, stop, num, base, dtype.value)
    else:
        result = linspace(start, stop, num, endpoint)
        return _maths.power(base, result)
Exemplo n.º 16
0
def logspace(start, stop, num=50, endpoint=True, base=10.0):
    '''Create a 1D dataset of values equally spaced on a logarithmic scale'''
    if not endpoint:
        stop = ((num - 1) * stop + start)/num

    if complex(start).imag == 0 and complex(stop).imag == 0:
        dtype = _getdtypefromobj(((start, stop)))
        return _dsutils.logSpace(start, stop, num, base, dtype.value)
    else:
        result = linspace(start, stop, num, endpoint)
        return _maths.power(base, result)
Exemplo n.º 17
0
def choose(a, choices, mode='raise'):
    '''Return dataset with items drawn from choices according to conditions'''
    if mode == 'raise':
        rf = True
        cf = False
    else:
        rf = False
        if mode == 'clip':
            cf = True
        elif mode == 'wrap':
            cf = False
        else:
            raise ValueError, "mode is not one of raise, clip or wrap"
    return _dsutils.choose(a, choices, rf, cf)
Exemplo n.º 18
0
def choose(a, choices, mode='raise'):
    '''Return dataset with items drawn from choices according to conditions'''
    if mode == 'raise':
        rf = True
        cf = False
    else:
        rf = False
        if mode == 'clip':
            cf = True
        elif mode == 'wrap':
            cf = False
        else:
            raise ValueError, "mode is not one of raise, clip or wrap"
    return _dsutils.choose(a, choices, rf, cf)
Exemplo n.º 19
0
def linspace(start, stop, num=50, endpoint=True, retstep=False):
    '''Create a 1D dataset from start to stop in given number of steps
    
    Arguments:
    start    -- starting value
    stop     -- stopping value
    num      -- number of steps, defaults to 50
    endpoint -- if True (default), include the stop value
    retstep  -- if False (default), do not include the calculated step value as part of return tuple
    '''
    if not endpoint:
        stop = ((num - 1) * stop + start) / num

    dtype = _getdtypefromobj(((start, stop)))

    if dtype.value < float64.value:
        dtype = float64

    if dtype.value >= complex64.value:
        dtype = complex128

        if type(start) is _types.IntType:
            start = start + 0j
        if type(stop) is _types.IntType:
            stop = stop + 0j
        rresult = _dsutils.linSpace(start.real, stop.real, num, float64.value)
        iresult = _dsutils.linSpace(start.imag, stop.imag, num, float64.value)
        result = Sciwrap(_complexdoubleds(rresult, iresult))
        del rresult, iresult
    else:
        result = Sciwrap(_dsutils.linSpace(start, stop, num, dtype.value))

    if retstep:
        step = result[1] - result[0]
        return (result, step)
    else:
        return result
Exemplo n.º 20
0
def linspace(start, stop, num=50, endpoint=True, retstep=False):
    '''Create a 1D dataset from start to stop in given number of steps
    
    Arguments:
    start    -- starting value
    stop     -- stopping value
    num      -- number of steps, defaults to 50
    endpoint -- if True (default), include the stop value
    retstep  -- if False (default), do not include the calculated step value as part of return tuple
    '''
    if not endpoint:
        stop = ((num - 1) * stop + start)/num

    dtype = _getdtypefromobj(((start, stop)))

    if dtype.value < float64.value:
        dtype = float64

    if dtype.value >= complex64.value:
        dtype = complex128

        if type(start) is _types.IntType:
            start = start+0j
        if type(stop) is _types.IntType:
            stop = stop+0j
        rresult = _dsutils.linSpace(start.real, stop.real, num, float64.value)
        iresult = _dsutils.linSpace(start.imag, stop.imag, num, float64.value)
        result = Sciwrap(_complexdoubleds(rresult, iresult))
        del rresult, iresult
    else:
        result = Sciwrap(_dsutils.linSpace(start, stop, num, dtype.value))

    if retstep:
        step = result[1] - result[0]
        return (result, step)
    else:
        return result
Exemplo n.º 21
0
def ravel_multi_index(multi_index, dims, mode='raise'):
    '''Converts a tuple of coordinate arrays to an array of flat indexes
    '''
    if isinstance(mode, tuple):
        mode = [_prep_mode.get(m, -1) for m in mode]
    else:
        mode = _prep_mode.get(mode, -1)

    if isinstance(multi_index, _ds): # split single array
        multi_index = [ _getslice(multi_index, i) for i in range(multi_index.shape[0]) ]

    single = False
    if isinstance(multi_index[0], int):
        single = True
        multi_index = [ array(m)._jdataset() for m in multi_index ]


    pos = _dsutils.calcIndexesFromPositions(multi_index, dims, mode)
    if single:
        return pos.getObject([])
    return pos
Exemplo n.º 22
0
def ravel_multi_index(multi_index, dims, mode='raise'):
    '''Converts a tuple of coordinate arrays to an array of flat indexes
    '''
    if isinstance(mode, tuple):
        mode = [_prep_mode.get(m, -1) for m in mode]
    else:
        mode = _prep_mode.get(mode, -1)

    if isinstance(multi_index, _ds):  # split single array
        multi_index = [
            _getslice(multi_index, i) for i in range(multi_index.shape[0])
        ]

    single = False
    if isinstance(multi_index[0], int):
        single = True
        multi_index = [array(m)._jdataset() for m in multi_index]

    pos = _dsutils.calcIndexesFromPositions(multi_index, dims, mode)
    if single:
        return pos.getObject([])
    return pos
Exemplo n.º 23
0
def meshgrid(*a):
    axes = [ asDataset(x) for x in reversed(a) ]
    coords = _dsutils.meshGrid(axes)
    return tuple([ Sciwrap(x) for x in reversed(coords) ])
Exemplo n.º 24
0
def transpose(a, axes=None):
    if axes is None:
        axes = ()
    return _dsutils.transpose(a, asIterable(axes))
Exemplo n.º 25
0
def cast(a, dtype):
    return _dsutils.cast(a, dtype.value)
Exemplo n.º 26
0
def repeat(a, repeats, axis=-1):
    return _dsutils.repeat(a, asIterable(repeats), axis)
Exemplo n.º 27
0
def sort(a, axis=-1):
    return _dsutils.sort(a, axis)
Exemplo n.º 28
0
def split(ary, indices_or_sections, axis=0):
    return _dsutils.split(ary, indices_or_sections, axis, True)
Exemplo n.º 29
0
def split(ary, indices_or_sections, axis=0):
    return _dsutils.split(ary, indices_or_sections, axis, True)
Exemplo n.º 30
0
def tile(a, reps):
    return _dsutils.tile(a, asIterable(reps))
Exemplo n.º 31
0
 def take(self, indices, axis=None):
     if isinstance(indices, ndarray):
         return _dsutils.take(self.__dataset, indices._jdataset(), axis)
     return _dsutils.take(self.__dataset, asIterable(indices), axis)
Exemplo n.º 32
0
def repeat(a, repeats, axis=-1):
    return _dsutils.repeat(a, asIterable(repeats), axis)
Exemplo n.º 33
0
def nan_to_num(a):
    '''Create a copy with infinities replaced by max/min values and NaNs replaced by 0s
    '''
    c = a.copy()
    _dsutils.removeNansAndInfinities(c)
    return c
Exemplo n.º 34
0
def compoundarray(a, view=True):
    '''Create a compound array from an nd array by grouping last axis items into compound items
    '''
    return _dsutils.createCompoundDatasetFromLastAxis(a, view)
Exemplo n.º 35
0
def roll(a, shift, axis=None):
    return _dsutils.roll(a, shift, axis)
Exemplo n.º 36
0
def sort(a, axis=-1):
    return _dsutils.sort(a, axis)
Exemplo n.º 37
0
def compoundarray(a, view=True):
    '''Create a compound array from an nd array by grouping last axis items into compound items
    '''
    return _dsutils.createCompoundDatasetFromLastAxis(a, view)
Exemplo n.º 38
0
def indices(dimensions, dtype=int32):
    ind = _dsutils.indices(asIterable(dimensions))
    dtype = _translatenativetype(dtype)
    if dtype != int32:
        ind = _dsutils.cast(ind, dtype.value)
    return ind
Exemplo n.º 39
0
def rollaxis(a, axis, start=0):
    return _dsutils.rollAxis(a, axis, start)
Exemplo n.º 40
0
def meshgrid(*a):
    axes = [asDataset(x) for x in reversed(a)]
    coords = _dsutils.meshGrid(axes)
    return tuple([Sciwrap(x) for x in reversed(coords)])
Exemplo n.º 41
0
def array_split(ary, indices_or_sections, axis=0):
    return _dsutils.split(ary, indices_or_sections, axis, False)
Exemplo n.º 42
0
def select(condlist, choicelist, default=0):
    '''Return dataset with items drawn from choices according to conditions'''
    return _dsutils.select(condlist, choicelist, default)
Exemplo n.º 43
0
def tile(a, reps):
    return _dsutils.tile(a, asIterable(reps))
Exemplo n.º 44
0
def dstack(tup):
    return _dsutils.concatenate(toList(tup), 2)
Exemplo n.º 45
0
def array_split(ary, indices_or_sections, axis=0):
    return _dsutils.split(ary, indices_or_sections, axis, False)
Exemplo n.º 46
0
def swapaxes(a, axis1, axis2):
    return _dsutils.swapAxes(a, axis1, axis2)
Exemplo n.º 47
0
def resize(a, new_shape):
    return _dsutils.resize(a, new_shape)
Exemplo n.º 48
0
def transpose(a, axes=None):
    if axes is None:
        axes = ()
    return _dsutils.transpose(a, asIterable(axes))
Exemplo n.º 49
0
def swapaxes(a, axis1, axis2):
    return _dsutils.swapAxes(a, axis1, axis2)
Exemplo n.º 50
0
 def take(self, indices, axis=None):
     if isinstance(indices, ndarray):
         return _dsutils.take(self.__dataset, indices._jdataset(), axis)
     return _dsutils.take(self.__dataset, asIterable(indices), axis)
Exemplo n.º 51
0
def indices(dimensions, dtype=int32):
    ind = _dsutils.indices(asIterable(dimensions))
    dtype = _translatenativetype(dtype)
    if dtype != int32:
        ind = _dsutils.cast(ind, dtype.value)
    return ind
Exemplo n.º 52
0
def resize(a, new_shape):
    return _dsutils.resize(a, new_shape)
Exemplo n.º 53
0
def rollaxis(a, axis, start=0):
    return _dsutils.rollAxis(a, axis, start)
Exemplo n.º 54
0
def concatenate(a, axis=0):
    return _dsutils.concatenate(toList(a), axis)
Exemplo n.º 55
0
def nan_to_num(a):
    '''Create a copy with infinities replaced by max/min values and NaNs replaced by 0s
    '''
    c = a.copy()
    _dsutils.removeNansAndInfinities(c)
    return c
Exemplo n.º 56
0
def dstack(tup):
    return _dsutils.concatenate(toList(tup), 2)
Exemplo n.º 57
0
def select(condlist, choicelist, default=0):
    '''Return dataset with items drawn from choices according to conditions'''
    return _dsutils.select(condlist, choicelist, default)
Exemplo n.º 58
0
def roll(a, shift, axis=None):
    return _dsutils.roll(a, shift, axis)
Exemplo n.º 59
0
def concatenate(a, axis=0):
    return _dsutils.concatenate(toList(a), axis)
Exemplo n.º 60
0
def cast(a, dtype):
    return _dsutils.cast(a, dtype.value)