當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.min_scalar_type方法代碼示例

本文整理匯總了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 
開發者ID:evfro,項目名稱:polara,代碼行數:22,代碼來源:evaluation.py

示例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 
開發者ID:cvangysel,項目名稱:SERT,代碼行數:23,代碼來源:inference.py

示例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 
開發者ID:ebmdatalab,項目名稱:openprescribing,代碼行數:20,代碼來源:test_matrix_ops.py

示例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)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:26,代碼來源:column.py

示例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)) 
開發者ID:westpa,項目名稱:westpa,代碼行數:5,代碼來源:systems.py

示例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() 
開發者ID:westpa,項目名稱:westpa,代碼行數:39,代碼來源:binning.py

示例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() 
開發者ID:westpa,項目名稱:westpa,代碼行數:34,代碼來源:w_eddist.py

示例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] 
開發者ID:westpa,項目名稱:westpa,代碼行數:7,代碼來源:assign.py

示例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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_multiarray.py

示例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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_multiarray.py

示例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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_multiarray.py

示例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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_multiarray.py

示例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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_multiarray.py

示例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 
開發者ID:mdbartos,項目名稱:pysheds,代碼行數:10,代碼來源:grid.py

示例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.) 
開發者ID:mdbartos,項目名稱:pysheds,代碼行數:31,代碼來源:test_grid.py


注:本文中的numpy.min_scalar_type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。