本文整理汇总了Python中numpy.min_scalar_type函数的典型用法代码示例。如果您正苦于以下问题:Python min_scalar_type函数的具体用法?Python min_scalar_type怎么用?Python min_scalar_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了min_scalar_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _convert_value
def _convert_value(self, value):
"""Convert a string into a numpy object (scalar or array).
The value is most of the time a string, but it can be python object
in case if TIFF decoder for example.
"""
if isinstance(value, list):
# convert to a numpy array
return numpy.array(value)
if isinstance(value, dict):
# convert to a numpy associative array
key_dtype = numpy.min_scalar_type(list(value.keys()))
value_dtype = numpy.min_scalar_type(list(value.values()))
associative_type = [('key', key_dtype), ('value', value_dtype)]
assert key_dtype.kind != "O" and value_dtype.kind != "O"
return numpy.array(list(value.items()), dtype=associative_type)
if isinstance(value, numbers.Number):
dtype = numpy.min_scalar_type(value)
assert dtype.kind != "O"
return dtype.type(value)
if isinstance(value, six.binary_type):
try:
value = value.decode('utf-8')
except UnicodeDecodeError:
return numpy.void(value)
if " " in value:
result = self._convert_list(value)
else:
result = self._convert_scalar_value(value)
return result
开发者ID:vallsv,项目名称:silx,代码行数:32,代码来源:fabioh5.py
示例2: shuffle_group
def shuffle_group(df, col, stage, k, npartitions):
""" Splits dataframe into groups
The group is determined by their final partition, and which stage we are in
in the shuffle
"""
if col == '_partitions':
ind = df[col]
else:
ind = hash_pandas_object(df[col], index=False)
c = ind._values
typ = np.min_scalar_type(npartitions * 2)
npartitions, k, stage = [np.array(x, dtype=np.min_scalar_type(x))[()]
for x in [npartitions, k, stage]]
c = np.mod(c, npartitions).astype(typ, copy=False)
c = np.floor_divide(c, k ** stage, out=c)
c = np.mod(c, k, out=c)
indexer, locations = groupsort_indexer(c.astype(np.int64), k)
df2 = df.take(indexer)
locations = locations.cumsum()
parts = [df2.iloc[a:b] for a, b in zip(locations[:-1], locations[1:])]
return dict(zip(range(k), parts))
开发者ID:floriango,项目名称:dask,代码行数:27,代码来源:shuffle.py
示例3: __init__
def __init__(self,Np):
if (type(Np) is not int):
raise ValueError("expecting integer for Np")
self._Np = Np
self._Ns = Np+1
self._dtype = _np.min_scalar_type(-self.Ns)
self._basis = _np.arange(self.Ns,dtype=_np.min_scalar_type(self.Ns))
self._operators = ("availible operators for ho_basis:"+
"\n\tI: identity "+
"\n\t+: raising operator"+
"\n\t-: lowering operator"+
"\n\tn: number operator")
开发者ID:zenonofelea,项目名称:exact_diag_py,代码行数:13,代码来源:photon.py
示例4: histograma
def histograma(imagen):
ajuste = 0
minimo_valor = np.min(imagen)
if minimo_valor < 0:
ajuste = minimo_valor
rango = np.max(imagen).astype(np.int64) - minimo_valor
ajuste_dtype = np.promote_types(np.min_scalar_type(rango),np.min_scalar_type(minimo_valor))
if imagen.dtype != ajuste_dtype:
imagen = imagen.astype(ajuste_dtype)
imagen = imagen - ajuste
hist = np.bincount(imagen.ravel())
valores_centrales = np.arange(len(hist)) + ajuste
idx = np.nonzero(hist)[0][0]
return hist[idx:], valores_centrales[idx:]
开发者ID:codeneomatrix,项目名称:IA,代码行数:14,代码来源:clasificador.py
示例5: _offset_array
def _offset_array(arr, low_boundary, high_boundary):
"""Offset the array to get the lowest value at 0 if negative."""
if low_boundary < 0:
offset = low_boundary
dyn_range = high_boundary - low_boundary
# get smallest dtype that can hold both minimum and offset maximum
offset_dtype = np.promote_types(np.min_scalar_type(dyn_range),
np.min_scalar_type(low_boundary))
if arr.dtype != offset_dtype:
# prevent overflow errors when offsetting
arr = arr.astype(offset_dtype)
arr = arr - offset
else:
offset = 0
return arr, offset
开发者ID:ThomasWalter,项目名称:scikit-image,代码行数:15,代码来源:exposure.py
示例6: __getitem__
def __getitem__(self, key):
"""
Look up a cell in the map, but clip to the edges
For instance, `map[-1, -1] == map[0, 0]`, unlike in a normal np array
where it would be `map[map.shape[0]-1, map.shape[1]-1]`
Note that this only applies for pairwise integer indexing. Indexing
with boolean masks or slice objects uses the normal indexing rules.
"""
if not isinstance(key, tuple):
# probably a mask?
return self.grid[key]
if len(key) != 2:
# row, column, or just wrong
return self.grid[key]
if any(np.min_scalar_type(i) == np.bool for i in key):
# partial mask
return self.grid[key]
if any(isinstance(i, slice) for i in key):
# normal slicing
return self.grid[key]
keys = np.ravel_multi_index(key, dims=self.grid.shape, mode='clip')
# workaround for https://github.com/numpy/numpy/pull/7586
if keys.ndim == 0:
return self.grid.take(keys[np.newaxis])[0]
else:
return self.grid.take(keys)
开发者ID:g41903,项目名称:MIT-RACECAR,代码行数:33,代码来源:map.py
示例7: full_cumsum
def full_cumsum(data, axis=None, dtype=None):
"""
A version of `numpy.cumsum` that includes the sum of the empty slice (zero). This
makes it satisfy the invariant::
cumsum(a)[i] == sum(a[:i])
which is a useful property to simplify the formula for the moving average. The result
will be one entry longer than *data* along *axis*.
"""
# All we need to do is construct a result array with the appropriate type and
# dimensions, and then feed a slice of it to cumsum, setting the rest to zero.
shape = list(data.shape)
if axis is None:
shape[0] += 1
else:
shape[axis] += 1
# Mimic cumsum's behavior with the dtype argument: use the original data type or
# the system's native word, whichever has the greater width. (This prevents us from
# attempting a cumulative sum using an 8-bit integer, for instance.)
if dtype is None:
dtype = np.promote_types(data.dtype, np.min_scalar_type(-sys.maxint))
out = np.zeros(shape, dtype)
s = axis_slice(axis)
np.cumsum(data, axis, dtype, out[s[1:]])
return out
开发者ID:tfmartino,项目名称:STOcapstone-calibration,代码行数:31,代码来源:edgedetect.py
示例8: go
def go(self):
pi = self.progress.indicator
pi.operation = 'Initializing'
with pi:
self.duration = self.kinetics_file['durations'][self.iter_start-1:self.iter_stop-1]
##Only select transition events from specified istate to fstate
mask = (self.duration['istate'] == self.istate) & (self.duration['fstate'] == self.fstate)
self.duration_dsspec = DurationDataset(self.kinetics_file['durations']['duration'], mask, self.iter_start)
self.wt_dsspec = DurationDataset(self.kinetics_file['durations']['weight'], mask, self.iter_start)
self.output_file = h5py.File(self.output_filename, 'w')
h5io.stamp_creator_data(self.output_file)
# Construct bin boundaries
self.construct_bins(self.parse_binspec(self.binspec))
for idim, (binbounds, midpoints) in enumerate(izip(self.binbounds, self.midpoints)):
self.output_file['binbounds_{}'.format(idim)] = binbounds
self.output_file['midpoints_{}'.format(idim)] = midpoints
# construct histogram
self.construct_histogram()
# Record iteration range
iter_range = numpy.arange(self.iter_start, self.iter_stop, 1, dtype=(numpy.min_scalar_type(self.iter_stop)))
self.output_file['n_iter'] = iter_range
self.output_file['histograms'].attrs['iter_start'] = self.iter_start
self.output_file['histograms'].attrs['iter_stop'] = self.iter_stop
self.output_file.close()
开发者ID:westpa,项目名称:west_tools,代码行数:32,代码来源:w_eddist.py
示例9: da_sub
def da_sub(daa, dab):
"""
subtract 2 DataArrays as cleverly as possible:
* keep the metadata of the first DA in the result
* ensures the result has the right type so that no underflows happen
returns (DataArray): the result of daa - dab
"""
rt = numpy.result_type(daa, dab) # dtype of result of daa-dab
dt = None # default is to let numpy decide
if rt.kind == "f":
# float should always be fine
pass
elif rt.kind in "iub":
# underflow can happen (especially if unsigned)
# find the worse case value (could be improved, but would be longer)
worse_val = int(daa.min()) - int(dab.max())
dt = numpy.result_type(rt, numpy.min_scalar_type(worse_val))
else:
# subtracting such a data is suspicious, but try anyway
logging.warning("Subtraction on data of type %s unsupported", rt.name)
res = numpy.subtract(daa, dab, dtype=dt) # metadata is copied from daa
logging.debug("type = %s, %s", res.dtype.name, daa.dtype.name)
return res
开发者ID:delmic,项目名称:odemis,代码行数:26,代码来源:convert.py
示例10: __init__
def __init__(self, func, nbins, args=None, kwargs=None):
self.func = func
self.args = args or ()
self.kwargs = kwargs or {}
self.nbins = nbins
self.index_dtype = numpy.min_scalar_type(self.nbins)
self.labels = ['{!r} bin {:d}'.format(func, ibin) for ibin in xrange(nbins)]
开发者ID:westpa,项目名称:westpa,代码行数:7,代码来源:assign.py
示例11: count_over_time_interval
def count_over_time_interval(
time,
values,
time_interval,
ignore_nodata,
nodata=None):
def aggregate_ignore_nodata(
values):
return (numpy.ones(values.shape[1:], dtype=numpy.uint8) *
values.shape[0]).tolist()
def aggregate_dont_ignore_nodata(
values):
return numpy.sum(values != nodata, 0)
aggregate = {
mds.constants.IGNORE_NODATA: aggregate_ignore_nodata,
mds.constants.DONT_IGNORE_NODATA: aggregate_dont_ignore_nodata
}
result_time, result_values = aggregate_over_time_interval(time, values,
TIME_POINT_TO_ID_BY_TIME_INTERVAL[time_interval],
aggregate[ignore_nodata])
return result_time, [numpy.array(result_values[i], numpy.min_scalar_type(
numpy.max(result_values[i]))) for i in xrange(len(result_values))]
开发者ID:NatalieCampos,项目名称:solutions-geoprocessing-toolbox,代码行数:27,代码来源:math.py
示例12: normalize_compare_value
def normalize_compare_value(self, other):
other_dtype = np.min_scalar_type(other)
if other_dtype.kind in 'biuf':
other_dtype = np.promote_types(self.dtype, other_dtype)
ary = utils.scalar_broadcast_to(other, shape=len(self),
dtype=other_dtype)
return self.replace(data=Buffer(ary), dtype=ary.dtype)
else:
raise TypeError('cannot broadcast {}'.format(type(other)))
开发者ID:xennygrimmato,项目名称:pygdf,代码行数:9,代码来源:numerical.py
示例13: iter_range
def iter_range(self, iter_start = None, iter_stop = None, iter_step = None, dtype=None):
'''Return a sequence for the given iteration numbers and stride, filling
in missing values from those stored on ``self``. The smallest data type capable of
holding ``iter_stop`` is returned unless otherwise specified using the ``dtype``
argument.'''
iter_start = self.iter_start if iter_start is None else iter_start
iter_stop = self.iter_stop if iter_stop is None else iter_stop
iter_step = self.iter_step if iter_step is None else iter_step
return numpy.arange(iter_start, iter_stop, iter_step, dtype=(dtype or numpy.min_scalar_type(iter_stop)))
开发者ID:ASinanSaglam,项目名称:west_tools,代码行数:9,代码来源:iter_range.py
示例14: shuffle_group
def shuffle_group(df, col, stage, k, npartitions):
if col == '_partitions':
ind = df[col]
else:
ind = hash_pandas_object(df[col], index=False)
c = ind._values
typ = np.min_scalar_type(npartitions * 2)
c = c.astype(typ)
npartitions, k, stage = [np.array(x, dtype=np.min_scalar_type(x))[()]
for x in [npartitions, k, stage]]
c = np.mod(c, npartitions, out=c)
c = np.floor_divide(c, k ** stage, out=c)
c = np.mod(c, k, out=c)
indexer, locations = pd.algos.groupsort_indexer(c.astype(np.int64), k)
df2 = df.take(indexer)
locations = locations.cumsum()
parts = [df2.iloc[a:b] for a, b in zip(locations[:-1], locations[1:])]
return dict(zip(range(k), parts))
开发者ID:wikiped,项目名称:dask,代码行数:23,代码来源:shuffle.py
示例15: create
def create(predict_fn, word_representations,
batch_size, window_size, vocabulary_size,
result_callback):
assert result_callback is not None
instance_dtype = np.min_scalar_type(vocabulary_size - 1)
logging.info('Instance elements will be stored using %s.', instance_dtype)
batcher = WordBatcher(
predict_fn,
batch_size, window_size, instance_dtype,
result_callback)
return batcher
开发者ID:avinash-k,项目名称:SERT,代码行数:14,代码来源:inference.py
示例16: render
def render(self):
# Convert data to QImage for display.
profile = debug.Profiler()
if self.image is None or self.image.size == 0:
return
if isinstance(self.lut, collections.Callable):
lut = self.lut(self.image)
else:
lut = self.lut
if self.autoDownsample:
# reduce dimensions of image based on screen resolution
o = self.mapToDevice(QtCore.QPointF(0,0))
x = self.mapToDevice(QtCore.QPointF(1,0))
y = self.mapToDevice(QtCore.QPointF(0,1))
w = Point(x-o).length()
h = Point(y-o).length()
xds = int(1/max(1, w))
yds = int(1/max(1, h))
image = fn.downsample(self.image, xds, axis=0)
image = fn.downsample(image, yds, axis=1)
else:
image = self.image
# if the image data is a small int, then we can combine levels + lut
# into a single lut for better performance
levels = self.levels
if levels is not None and levels.ndim == 1 and image.dtype in (np.ubyte, np.uint16):
if self._effectiveLut is None:
eflsize = 2**(image.itemsize*8)
ind = np.arange(eflsize)
minlev, maxlev = levels
if lut is None:
efflut = fn.rescaleData(ind, scale=255./(maxlev-minlev),
offset=minlev, dtype=np.ubyte)
else:
lutdtype = np.min_scalar_type(lut.shape[0]-1)
efflut = fn.rescaleData(ind, scale=(lut.shape[0]-1)/(maxlev-minlev),
offset=minlev, dtype=lutdtype, clip=(0, lut.shape[0]-1))
efflut = lut[efflut]
self._effectiveLut = efflut
lut = self._effectiveLut
levels = None
argb, alpha = fn.makeARGB(image.transpose((1, 0, 2)[:image.ndim]), lut=lut, levels=levels)
self.qimage = fn.makeQImage(argb, alpha, transpose=False)
开发者ID:acrsilva,项目名称:animated-zZz-machine,代码行数:48,代码来源:ImageItem.py
示例17: __init__
def __init__(self,b1,b2):
if not isinstance(b1,basis):
raise ValueError("b1 must be instance of basis class")
if not isinstance(b2,basis):
raise ValueError("b2 must be instance of basis class")
if isinstance(b1,tensor_basis):
raise TypeError("Can only create tensor basis with non-tensor type basis")
if isinstance(b2,tensor_basis):
raise TypeError("Can only create tensor basis with non-tensor type basis")
self._b1=b1
self._b2=b2
self._Ns = b1.Ns*b2.Ns
self._dtype = _np.min_scalar_type(-self._Ns)
self._operators = self._b1._operators +"\n"+ self._b2._operators
开发者ID:zenonofelea,项目名称:exact_diag_py,代码行数:16,代码来源:tensor.py
示例18: _get_dtype
def _get_dtype(operand):
"""
Get the numpy dtype corresponding to the numeric data in the object
provided.
Args:
* operand:
An instance of :class:`iris.cube.Cube` or :class:`iris.coords.Coord`,
or a number or :class:`numpy.ndarray`.
Returns:
An instance of :class:`numpy.dtype`
"""
return np.min_scalar_type(operand) if np.isscalar(operand) \
else operand.dtype
开发者ID:cpelley,项目名称:iris,代码行数:17,代码来源:maths.py
示例19: shuffle_group
def shuffle_group(df, col, stage, k, npartitions):
""" Splits dataframe into groups
The group is determined by their final partition, and which stage we are in
in the shuffle
Parameters
----------
df: DataFrame
col: str
Column name on which to split the dataframe
stage: int
We shuffle dataframes with many partitions we in a few stages to avoid
a quadratic number of tasks. This number corresponds to which stage
we're in, starting from zero up to some small integer
k: int
Desired number of splits from this dataframe
npartition: int
Total number of output partitions for the full dataframe
Returns
-------
out: Dict[int, DataFrame]
A dictionary mapping integers in {0..k} to dataframes such that the
hash values of ``df[col]`` are well partitioned.
"""
if col == '_partitions':
ind = df[col]
else:
ind = hash_pandas_object(df[col], index=False)
c = ind._values
typ = np.min_scalar_type(npartitions * 2)
c = np.mod(c, npartitions).astype(typ, copy=False)
np.floor_divide(c, k ** stage, out=c)
np.mod(c, k, out=c)
indexer, locations = groupsort_indexer(c.astype(np.int64), k)
df2 = df.take(indexer)
locations = locations.cumsum()
parts = [df2.iloc[a:b] for a, b in zip(locations[:-1], locations[1:])]
return dict(zip(range(k), parts))
开发者ID:yliapis,项目名称:dask,代码行数:44,代码来源:shuffle.py
示例20: __init__
def __init__(self, n_bins, output_group, calc_fpts = True):
self.calc_fpts = calc_fpts
self.n_bins = n_bins
self.iibins = numpy.arange(n_bins)
self.iibdisc = numpy.empty((n_bins,), numpy.bool_)
self.bin_index_dtype = numpy.min_scalar_type(n_bins)
self.tdat_dtype = numpy.dtype( [('traj', self.index_dtype),
('n_iter', self.index_dtype),
('timepoint', self.index_dtype),
('initial_bin', self.bin_index_dtype),
('final_bin', self.bin_index_dtype),
('initial_weight', self.weight_dtype),
('final_weight', self.weight_dtype),
('initial_bin_pop', self.weight_dtype),
('duration', self.index_dtype),
('fpt', self.index_dtype),
])
# HDF5 group in which to store results
self.output_group = output_group
self.tdat_buffer = numpy.empty((self.tdat_buffersize,), dtype=self.tdat_dtype)
self.tdat_buffer_offset = 0
self.output_tdat_offset = 0
self.output_tdat_ds = None
# Accumulators/counters
self.n_trans = None # shape (n_bins,n_bins)
# Time points and per-timepoint data
self.last_exit = None # (n_bins,)
self.last_entry = None # (n_bins,)
self.last_completion = None # (n_bins,n_bins)
self.weight_last_exit = None # (n_bins)
self.bin_pops_last_exit = None # (n_bins,)
# Analysis continuation information
self.timepoint = None # current time index for separate calls on same trajectory
self.last_bin = None # last region occupied, for separate calls on same trajectory
self.last_bin_pop = None # total weight in self.last_region at end of last processing step
self.clear()
开发者ID:nrego,项目名称:westpa,代码行数:44,代码来源:transitions.py
注:本文中的numpy.min_scalar_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论