当前位置: 首页>>代码示例>>Python>>正文


Python numpy.index_exp方法代码示例

本文整理汇总了Python中numpy.index_exp方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.index_exp方法的具体用法?Python numpy.index_exp怎么用?Python numpy.index_exp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.index_exp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _leading_trailing

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def _leading_trailing(a, edgeitems, index=()):
    """
    Keep only the N-D corners (leading and trailing edges) of an array.

    Should be passed a base-class ndarray, since it makes no guarantees about
    preserving subclasses.
    """
    axis = len(index)
    if axis == a.ndim:
        return a[index]

    if a.shape[axis] > 2*edgeitems:
        return concatenate((
            _leading_trailing(a, edgeitems, index + np.index_exp[ :edgeitems]),
            _leading_trailing(a, edgeitems, index + np.index_exp[-edgeitems:])
        ), axis=axis)
    else:
        return _leading_trailing(a, edgeitems, index + np.index_exp[:]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:arrayprint.py

示例2: process_args

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def process_args(self, args):
        self.progress.process_args(args)
        self.data_reader.process_args(args)
        self.input_dssynth.h5filename = self.data_reader.we_h5filename
        self.input_dssynth.process_args(args)
        self.dsspec = self.input_dssynth.dsspec
        
        # Carrying an open HDF5 file across a fork() seems to corrupt the entire HDF5 library
        # Open the WEST HDF5 file just long enough to process our iteration range, then close
        # and reopen in go() [which executes after the fork]
        with self.data_reader:
            self.iter_range.process_args(args)
        
        self.wt_dsspec = SingleIterDSSpec(self.data_reader.we_h5filename, 'seg_index', slice=numpy.index_exp['weight'])
        
        self.binspec = args.bins
        self.output_filename = args.output
        self.ignore_out_of_range = bool(args.ignore_out_of_range)
        self.compress_output = args.compress or False 
开发者ID:westpa,项目名称:westpa,代码行数:21,代码来源:w_pdist.py

示例3: get_iteration_slice

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def get_iteration_slice(h5object, iter_start, iter_stop=None, iter_stride=None):
    '''Create a slice for data corresponding to iterations [iter_start,iter_stop),
    with stride iter_step, in the given ``h5object``.'''
    obj_iter_start, obj_iter_stop = get_iter_range(h5object)
    
    if iter_stop is None: iter_stop = iter_start+1
    if iter_stride is None: iter_stride = 1
    
    if iter_start < obj_iter_start:
        raise IndexError('data for iteration {} not available in dataset {!r}'.format(iter_start, h5object))
    elif iter_start > obj_iter_stop:
        raise IndexError('data for iteration {} not available in dataset {!r}'.format(iter_stop, h5object))
    
    start_index = iter_start - obj_iter_start
    stop_index = iter_stop - obj_iter_start
    return numpy.index_exp[start_index:stop_index:iter_stride]



        
    
###
# Axis label metadata
### 
开发者ID:westpa,项目名称:westpa,代码行数:26,代码来源:h5io.py

示例4: from_string

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def from_string(cls, dsspec_string, default_h5file):
        alias = None
        
        h5file = default_h5file
        fields = dsspec_string.split(',')
        dsname = fields[0]
        slice = None
        
        for field in (field.strip() for field in fields[1:]):
            k,v = field.split('=')
            k = k.lower()
            if k == 'alias':
                alias = v
            elif k == 'slice':
                try:
                    slice = eval('numpy.index_exp' + v)
                except SyntaxError:
                    raise SyntaxError('invalid index expression {!r}'.format(v))
            elif k == 'file':
                h5file = v
            else:
                raise ValueError('invalid dataset option {!r}'.format(k))
            
        return cls(h5file, dsname, alias, slice) 
开发者ID:westpa,项目名称:westpa,代码行数:26,代码来源:h5io.py

示例5: __getitem__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def __getitem__(
        self, key: Union[int, slice, Tuple[Union[int, slice]]]
    ) -> "GridAxis":
        if not is_basic_indexing(key):
            raise IndexError("Only basic indexing is supported!")

        key = np.index_exp[key]
        requires_new_axis = False

        # first index corresponds to temporal slicing if ndim == axis_dim + 1
        # or alternatively -> check len of the axis -> number of temporal slices
        if len(self) != 1:
            # revert dimensionality reduction
            if isinstance(key[0], int):
                requires_new_axis = True
        else:
            requires_new_axis = True

        return self.__class__(
            self.data[key][np.newaxis] if requires_new_axis else self.data[key],
            name=self.name,
            label=self.label,
            unit=self.unit,
            axis_type=self.axis_type,
        ) 
开发者ID:GoLP-IST,项目名称:nata,代码行数:27,代码来源:axes.py

示例6: is_basic_indexing

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def is_basic_indexing(key: Any):
    indexing = np.index_exp[key]
    passes = []
    for ind in indexing:
        if isinstance(ind, (int, slice)):
            passes.append(True)
        elif ind is Ellipsis:
            passes.append(True)
        elif ind is np.newaxis:
            passes.append(True)
        else:
            passes.append(False)

    if all(passes):
        return True
    return False 
开发者ID:GoLP-IST,项目名称:nata,代码行数:18,代码来源:types.py

示例7: additive_composite

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def additive_composite(src, src_mask, dst):
    '''
    Return the additive composite of src and dst.
    '''
    out = np.empty(dst.shape, dtype = 'float')
    alpha = np.index_exp[3:, :, :]
    rgb = np.index_exp[:3, :, :]
    if src_mask is not None:
        out[alpha] = np.maximum(src_mask,dst[alpha])
    else:
        out[alpha] = 1.0
    out[rgb] = np.maximum(src[rgb],dst[rgb])
    np.clip(out,0,1.0)
    return out

# gsize = 64
# gsize2 = gsize/2 
开发者ID:dribnet,项目名称:plat,代码行数:19,代码来源:canvas.py

示例8: get_next_batch

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def get_next_batch(self, mode, idx):
        """
        return next batch of data samples
        """
        batch_size = self.args.batch_size
        if mode == "train":
            dataset = self.train_data
            sample_num = self.train_sample_num
        elif mode == "valid":
            dataset = self.valid_data
            sample_num = self.valid_sample_num
        else:
            dataset = self.test_data
            sample_num = self.test_sample_num
        if mode == "train":
            start = self.train_idx[idx] * batch_size
            stop = (self.train_idx[idx] + 1) * batch_size
        else:
            start = idx * batch_size
            stop = (idx + 1) * batch_size if start < sample_num and (idx + 1) * batch_size < sample_num else -1
        samples = batch_size if stop != -1 else len(dataset[0]) - start
        _slice = np.index_exp[start:stop]
        return self.next_batch_feed_dict_by_dataset(dataset, _slice, samples) 
开发者ID:cairoHy,项目名称:RC-experiments,代码行数:25,代码来源:rc_dataset.py

示例9: to_slice

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def to_slice(self):
    """Returns slice in C-order (ZYX)."""
    return np.index_exp[self.start[2]:self.end[2],  #
                        self.start[1]:self.end[1],  #
                        self.start[0]:self.end[0]] 
开发者ID:google,项目名称:ffn,代码行数:7,代码来源:bounding_box.py

示例10: process_args

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def process_args(self, args):
        self.output_filename = args.output
        (pathname, slicestr) = re.search(r'([^[]+)(\[[^\]]+\])?$', args.dsspec).groups()
        if slicestr:
            sl = eval('numpy.index_exp' + slicestr)
        else:
            sl = numpy.index_exp[...]
        self.h5file, self.h5dset = h5io.resolve_filepath(pathname, mode='r')
        self.dset_slice = sl 
开发者ID:westpa,项目名称:westpa,代码行数:11,代码来源:ploterr.py

示例11: weight_dsspec

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def weight_dsspec(self):
        if self._weight_dsspec is None:
            assert self.we_h5filename is not None
            self._weight_dsspec = SingleIterDSSpec(self.we_h5filename, 'seg_index', slice=index_exp['weight'])
        return self._weight_dsspec 
开发者ID:westpa,项目名称:westpa,代码行数:7,代码来源:data_reader.py

示例12: parent_id_dsspec

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def parent_id_dsspec(self):
        if self._parent_id_dsspec is None:
            assert self.we_h5filename is not None
            #self._parent_id_dsspec = SingleIterDSSpec(self.we_h5filename, 'seg_index', slice=index_exp['parent_id'])
            self._parent_id_dsspec = FnDSSpec(self.we_h5filename, _get_parent_ids)
        return self._parent_id_dsspec 
开发者ID:westpa,项目名称:westpa,代码行数:8,代码来源:data_reader.py

示例13: _assign_label_pop

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def _assign_label_pop(n_iter, lb, ub, mapper, nstates, state_map, last_labels, parent_id_dsspec, weight_dsspec, pcoord_dsspec, subsample):

    nbins = len(state_map)-1
    parent_ids = parent_id_dsspec.get_iter_data(n_iter,index_exp[lb:ub])
    weights = weight_dsspec.get_iter_data(n_iter,index_exp[lb:ub])
    pcoords = pcoord_dsspec.get_iter_data(n_iter,index_exp[lb:ub])
    
    assignments, trajlabels, statelabels = assign_and_label(lb, ub, parent_ids,
                                               mapper.assign, nstates, state_map, last_labels, pcoords, subsample)
    pops = numpy.zeros((nstates+1,nbins+1), weight_dtype)
    accumulate_labeled_populations(weights, assignments, trajlabels, pops)
    return (assignments, trajlabels, pops, lb, ub, statelabels) 
开发者ID:westpa,项目名称:westpa,代码行数:14,代码来源:w_assign.py

示例14: get_iteration_entry

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def get_iteration_entry(h5object, n_iter):
    '''Create a slice for data corresponding to iteration ``n_iter`` in ``h5object``.'''
    obj_iter_start, obj_iter_stop = get_iter_range(h5object)
    if n_iter < obj_iter_start or n_iter >= obj_iter_stop:
        raise IndexError('data for iteration {} not available in dataset {!r}'.format(n_iter, h5object))
    return numpy.index_exp[n_iter-obj_iter_start] 
开发者ID:westpa,项目名称:westpa,代码行数:8,代码来源:h5io.py

示例15: get_iter_data

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import index_exp [as 别名]
def get_iter_data(self, n_iter, seg_slice=index_exp[:]):
        raise NotImplementedError 
开发者ID:westpa,项目名称:westpa,代码行数:4,代码来源:h5io.py


注:本文中的numpy.index_exp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。