本文整理匯總了Python中numpy.min_scalar_type方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.min_scalar_type方法的具體用法?Python numpy.min_scalar_type怎麽用?Python numpy.min_scalar_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.min_scalar_type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_rank_matrix
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def build_rank_matrix(recommendations, shape):
# handle singletone case for a single user
recommendations = np.array(recommendations, copy=False, ndmin=2)
n_keys, topn = recommendations.shape
rank_arr = np.arange(1, topn+1, dtype=np.min_scalar_type(topn))
recs_rnk = np.lib.stride_tricks.as_strided(rank_arr, (n_keys, topn), (0, rank_arr.itemsize))
# support models that may generate < top-n recommendations
# such models generate self._pad_const, which is negative by convention
valid_recommendations = recommendations >= 0
if not valid_recommendations.all():
data = recs_rnk[valid_recommendations]
indices = recommendations[valid_recommendations]
indptr = np.r_[0, np.cumsum(valid_recommendations.sum(axis=1))]
else:
data = recs_rnk.ravel()
indices = recommendations.ravel()
indptr = np.arange(0, n_keys*topn+1, topn)
rank_matrix = no_copy_csr_matrix(data, indices, indptr, shape, rank_arr.dtype)
return rank_matrix
示例2: create
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
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)
if result_callback.should_average_input():
batcher = EmbeddingMapper(
predict_fn,
word_representations,
result_callback)
else:
batcher = WordBatcher(
predict_fn,
batch_size, window_size,
instance_dtype,
result_callback)
return batcher
示例3: _random_matrix
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def _random_matrix(self, minimum, maximum, floor):
"""
Return an integer matrix with random values between `minimum` and
`maximum` with at least one being larger than `floor` and at least one
being negative if `minimum` is negative
"""
value = self.random.randint(floor + 1, maximum)
if minimum < 0:
small_value = self.random.randint(minimum, -1)
else:
small_value = 0
# Ensure that the dtype is big enough to hold the maximum value (int_
# will do for all cases apart from uint64)
dtype = numpy.promote_types(numpy.int_, numpy.min_scalar_type(maximum))
matrix = numpy.zeros((2, 2), dtype=dtype)
matrix[0, 0] = value
matrix[0, 1] = small_value
return matrix
示例4: _scalar_to_format
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def _scalar_to_format(value):
"""
Given a scalar value or string, returns the minimum FITS column format
that can represent that value. 'minimum' is defined by the order given in
FORMATORDER.
"""
# First, if value is a string, try to convert to the appropriate scalar
# value
for type_ in (int, float, complex):
try:
value = type_(value)
break
except ValueError:
continue
numpy_dtype_str = np.min_scalar_type(value).str
numpy_dtype_str = numpy_dtype_str[1:] # Strip endianness
try:
fits_format = NUMPY2FITS[numpy_dtype_str]
return FITSUPCONVERTERS.get(fits_format, fits_format)
except KeyError:
return "A" + str(len(value))
示例5: bin_target_counts
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def bin_target_counts(self, target_counts):
maxcount = max(target_counts)
self._bin_target_counts = numpy.array(target_counts, dtype=numpy.min_scalar_type(maxcount))
示例6: assign_to_bins
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def assign_to_bins(self):
'''Assign WEST segment data to bins. Requires the DataReader mixin to be in the inheritance tree'''
self.require_binning_group()
n_iters = self.last_iter - self.first_iter + 1
max_n_segs = self.max_iter_segs_in_range(self.first_iter, self.last_iter)
pcoord_len = self.get_pcoord_len(self.first_iter)
assignments = numpy.zeros((n_iters, max_n_segs,pcoord_len), numpy.min_scalar_type(self.n_bins))
populations = numpy.zeros((n_iters, pcoord_len, self.n_bins), numpy.float64)
westpa.rc.pstatus('Assigning to bins...')
for (iiter, n_iter) in enumerate(range(self.first_iter, self.last_iter+1)):
westpa.rc.pstatus('\r Iteration {:d}'.format(n_iter), end='')
seg_index = self.get_seg_index(n_iter)
pcoords = self.get_iter_group(n_iter)['pcoord'][...]
weights = seg_index['weight']
for seg_id in range(len(seg_index)):
assignments[iiter,seg_id,:] = self.mapper.assign(pcoords[seg_id,:,:])
for it in range(pcoord_len):
populations[iiter, it, :] = numpy.bincount(assignments[iiter,:len(seg_index),it], weights, minlength=self.n_bins)
westpa.rc.pflush()
del pcoords, weights, seg_index
assignments_ds = self.binning_h5group.create_dataset('bin_assignments', data=assignments, compression='gzip')
populations_ds = self.binning_h5group.create_dataset('bin_populations', data=populations, compression='gzip')
for h5object in (self.binning_h5group, assignments_ds, populations_ds):
self.record_data_iter_range(h5object)
self.record_data_iter_step(h5object, 1)
self.record_data_binhash(h5object)
westpa.rc.pstatus()
示例7: go
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
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(zip(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()
示例8: __init__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def __init__(self, functions):
self.functions = functions
self.nbins = len(functions)
self.index_dtype = numpy.min_scalar_type(self.nbins)
self.labels = [repr(func) for func in functions]
示例9: test_usigned_shortshort
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def test_usigned_shortshort(self):
dt = np.min_scalar_type(2**8-1)
wanted = np.dtype('uint8')
assert_equal(wanted, dt)
示例10: test_usigned_short
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def test_usigned_short(self):
dt = np.min_scalar_type(2**16-1)
wanted = np.dtype('uint16')
assert_equal(wanted, dt)
示例11: test_usigned_int
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def test_usigned_int(self):
dt = np.min_scalar_type(2**32-1)
wanted = np.dtype('uint32')
assert_equal(wanted, dt)
示例12: test_usigned_longlong
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def test_usigned_longlong(self):
dt = np.min_scalar_type(2**63-1)
wanted = np.dtype('uint64')
assert_equal(wanted, dt)
示例13: test_object
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def test_object(self):
dt = np.min_scalar_type(2**64)
wanted = np.dtype('O')
assert_equal(wanted, dt)
示例14: _num_cycles
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def _num_cycles(self, fdir, startnodes, max_cycle_len=10):
cy = np.zeros(startnodes.size, dtype=np.min_scalar_type(max_cycle_len + 1))
endnodes = fdir.flat[startnodes]
for n in range(1, max_cycle_len + 1):
check = ((startnodes == endnodes) & (cy == 0))
cy[check] = n
endnodes = fdir.flat[endnodes]
return cy
示例15: test_accumulation
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import min_scalar_type [as 別名]
def test_accumulation():
# TODO: This breaks if clip_to's padding of dir is nonzero
grid.clip_to('dir')
grid.accumulation(data='dir', dirmap=dirmap, out_name='acc')
assert(grid.acc.max() == acc_in_frame)
# set nodata to 1
eff = grid.view("eff")
eff[eff==grid.eff.nodata] = 1
grid.accumulation(data='dir', dirmap=dirmap, out_name='acc_eff', efficiency=eff)
assert(abs(grid.acc_eff.max() - acc_in_frame_eff) < 0.001)
assert(abs(grid.acc_eff[grid.acc==grid.acc.max()] - acc_in_frame_eff1) < 0.001)
# TODO: Should eventually assert: grid.acc.dtype == np.min_scalar_type(grid.acc.max())
grid.clip_to('catch', pad=(1,1,1,1))
grid.accumulation(data='catch', dirmap=dirmap, out_name='acc')
assert(grid.acc.max() == cells_in_catch)
# Test accumulation on computed flowdirs
grid.accumulation(data='d8_dir', dirmap=dirmap, out_name='d8_acc', routing='d8')
grid.accumulation(data='dinf_dir', dirmap=dirmap, out_name='dinf_acc', routing='dinf')
grid.accumulation(data='dinf_dir', dirmap=dirmap, out_name='dinf_acc', as_crs=new_crs,
routing='dinf')
assert(grid.d8_acc.max() > 11300)
assert(grid.dinf_acc.max() > 11400)
#set nodata to 1
eff = grid.view("dinf_eff")
eff[eff==grid.dinf_eff.nodata] = 1
grid.accumulation(data='dinf_dir', dirmap=dirmap, out_name='dinf_acc_eff', routing='dinf',
efficiency=eff)
pos = np.where(grid.dinf_acc==grid.dinf_acc.max())
assert(np.round(grid.dinf_acc[pos] / grid.dinf_acc_eff[pos]) == 4.)