本文整理匯總了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[:])
示例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
示例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
###
示例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)
示例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,
)
示例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
示例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
示例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)
示例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]]
示例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
示例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
示例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
示例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)
示例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]
示例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