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


Python numpy.iinfo方法代码示例

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


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

示例1: hparams

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def hparams(self, defaults, model_hparams):
    p = model_hparams
    # Filterbank extraction in bottom instead of preprocess_example is faster.
    p.add_hparam("audio_preproc_in_bottom", False)
    # The trainer seems to reserve memory for all members of the input dict
    p.add_hparam("audio_keep_example_waveforms", False)
    p.add_hparam("audio_sample_rate", 16000)
    p.add_hparam("audio_preemphasis", 0.97)
    p.add_hparam("audio_dither", 1.0 / np.iinfo(np.int16).max)
    p.add_hparam("audio_frame_length", 25.0)
    p.add_hparam("audio_frame_step", 10.0)
    p.add_hparam("audio_lower_edge_hertz", 20.0)
    p.add_hparam("audio_upper_edge_hertz", 8000.0)
    p.add_hparam("audio_num_mel_bins", 80)
    p.add_hparam("audio_add_delta_deltas", True)
    p.add_hparam("num_zeropad_frames", 250)

    p = defaults
    # p.stop_at_eos = int(False)
    p.input_modality = {"inputs": ("audio:speech_recognition_modality", None)}
    p.target_modality = (registry.Modalities.SYMBOL, 256) 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:23,代码来源:speech_recognition.py

示例2: fit

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def fit(self, X, y):
        if X.shape[0] == 0:
            return self
        elif np.unique(y).shape[0] <= 1:
            self.update_aux(y)
            return self

        seed = self.random_state.integers(np.iinfo(np.int32).max)
        self.model.set_params(random_state = seed)
        self.model.fit(X, y)
        n_nodes = self.model.tree_.node_count
        self.pos = np.zeros(n_nodes, dtype=ctypes.c_long)
        self.neg = np.zeros(n_nodes, dtype=ctypes.c_long)
        pred_node = self.model.apply(X).astype(ctypes.c_long)
        _create_node_counters(self.pos, self.neg, pred_node, y.astype(ctypes.c_double))
        self.pos = self.pos.astype(ctypes.c_double) + self.beta_prior[0]
        self.neg = self.neg.astype(ctypes.c_double) + self.beta_prior[1]

        self.is_fitted = True
        return self 
开发者ID:david-cortes,项目名称:contextualbandits,代码行数:22,代码来源:utils.py

示例3: _do_scaling

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def _do_scaling(self):
        arr = self._array
        out_dtype = self._out_dtype
        assert out_dtype.kind in 'iu'
        mn, mx = self.finite_range()
        if arr.dtype.kind == 'f':
            # Float to (u)int scaling
            self._range_scale()
            return
        # (u)int to (u)int
        info = np.iinfo(out_dtype)
        out_max, out_min = info.max, info.min
        # If left as int64, uint64, comparisons will default to floats, and
        # these are inexact for > 2**53 - so convert to int
        if (as_int(mx) <= as_int(out_max) and
            as_int(mn) >= as_int(out_min)):
            # already in range
            return
        # (u)int to (u)int scaling
        self._iu2iu() 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:22,代码来源:arraywriters.py

示例4: _get_valid_range

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def _get_valid_range(self):
        ''' Return valid range for image data

        The valid range can come from the image 'valid_range' or
        image 'valid_min' and 'valid_max', or, failing that, from the
        data type range
        '''
        ddt = self.get_data_dtype()
        info = np.iinfo(ddt.type)
        try:
            valid_range = self._image.valid_range
        except AttributeError:
            try:
                valid_range = [self._image.valid_min,
                               self._image.valid_max]
            except AttributeError:
                valid_range = [info.min, info.max]
        if valid_range[0] < info.min or valid_range[1] > info.max:
            raise ValueError('Valid range outside input '
                             'data type range')
        return np.asarray(valid_range, dtype=np.float) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:23,代码来源:minc.py

示例5: test_int_int_min_max

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def test_int_int_min_max():
    # Conversion between (u)int and (u)int
    eps = np.finfo(np.float64).eps
    rtol = 1e-6
    for in_dt in IUINT_TYPES:
        iinf = np.iinfo(in_dt)
        arr = np.array([iinf.min, iinf.max], dtype=in_dt)
        for out_dt in IUINT_TYPES:
            try:
                aw = SlopeInterArrayWriter(arr, out_dt)
            except ScalingError:
                continue
            arr_back_sc = round_trip(aw)
            # integer allclose
            adiff = int_abs(arr - arr_back_sc)
            rdiff = adiff / (arr + eps)
            assert_true(np.all(rdiff < rtol)) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:19,代码来源:test_arraywriters.py

示例6: test_int_int_slope

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def test_int_int_slope():
    # Conversion between (u)int and (u)int for slopes only
    eps = np.finfo(np.float64).eps
    rtol = 1e-7
    for in_dt in IUINT_TYPES:
        iinf = np.iinfo(in_dt)
        for out_dt in IUINT_TYPES:
            kinds = np.dtype(in_dt).kind + np.dtype(out_dt).kind
            if kinds in ('ii', 'uu', 'ui'):
                arrs = (np.array([iinf.min, iinf.max], dtype=in_dt),)
            elif kinds == 'iu':
                arrs = (np.array([iinf.min, 0], dtype=in_dt),
                        np.array([0, iinf.max], dtype=in_dt))
            for arr in arrs:
                try:
                    aw = SlopeArrayWriter(arr, out_dt)
                except ScalingError:
                    continue
                assert_false(aw.slope == 0)
                arr_back_sc = round_trip(aw)
                # integer allclose
                adiff = int_abs(arr - arr_back_sc)
                rdiff = adiff / (arr + eps)
                assert_true(np.all(rdiff < rtol)) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:26,代码来源:test_arraywriters.py

示例7: test_able_casting

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def test_able_casting():
    # Check the able_int_type function guesses numpy out type
    types = np.sctypes['int'] + np.sctypes['uint']
    for in_type in types:
        in_info = np.iinfo(in_type)
        in_mn, in_mx = in_info.min, in_info.max
        A = np.zeros((1,), dtype=in_type)
        for out_type in types:
            out_info = np.iinfo(out_type)
            out_mn, out_mx = out_info.min, out_info.max
            B = np.zeros((1,), dtype=out_type)
            ApBt = (A + B).dtype.type
            able_type = able_int_type([in_mn, in_mx, out_mn, out_mx])
            if able_type is None:
                assert_equal(ApBt, np.float64)
                continue
            # Use str for comparison to avoid int32/64 vs intp comparison
            # failures
            assert_equal(np.dtype(ApBt).str, np.dtype(able_type).str) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:21,代码来源:test_casting.py

示例8: _linear_transformation_to_lut

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def _linear_transformation_to_lut(linear_transformation,
                                  max_value=None, dtype=numpy.uint16):
    min_value = 0
    if max_value is None:
        max_value = numpy.iinfo(dtype).max

    def gain_offset_to_lut(gain, offset):
        logging.debug(
            'Normalize: Calculating lut values for gain '
            '{} and offset {}'.format(gain, offset))
        lut = numpy.arange(min_value, max_value + 1, dtype=numpy.float)
        return gain * lut + offset

    lut = gain_offset_to_lut(linear_transformation.gain,
                             linear_transformation.offset)

    logging.debug('Normalize: Clipping lut from [{}, {}] to [{},{}]'.format(
        min(lut), max(lut), min_value, max_value))
    numpy.clip(lut, min_value, max_value, lut)

    return lut.astype(dtype) 
开发者ID:planetlabs,项目名称:radiometric_normalization,代码行数:23,代码来源:normalize.py

示例9: _uniform_weight_alpha

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def _uniform_weight_alpha(sum_masked_arrays, output_datatype):
    '''Calculates the cumulative mask of a list of masked array

    Input:
        sum_masked_arrays (list of numpy masked arrays): The list of
            masked arrays to find the cumulative mask of, each element
            represents one band.
            (sums_masked_array.mask has a 1 for a no data pixel and
            a 0 otherwise)
        output_datatype (numpy datatype): The output datatype

    Output:
        output_alpha (numpy uint16 array): The output mask
            (0 for a no data pixel, uint16 max value otherwise)
    '''

    output_alpha = numpy.ones(sum_masked_arrays[0].shape)
    for band_sum_masked_array in sum_masked_arrays:
        output_alpha[numpy.nonzero(band_sum_masked_array.mask == 1)] = 0

    output_alpha = output_alpha.astype(output_datatype) * \
        numpy.iinfo(output_datatype).max

    return output_alpha 
开发者ID:planetlabs,项目名称:radiometric_normalization,代码行数:26,代码来源:time_stack.py

示例10: _parallel_predict

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def _parallel_predict(self, contexts: np.ndarray, is_predict: bool):

        # Total number of contexts to predict
        n_contexts = len(contexts)

        # Partition contexts by job
        n_jobs, n_contexts, starts = self._partition_contexts(n_contexts)
        total_contexts = sum(n_contexts)

        # Get seed value for each context
        seeds = self.rng.randint(np.iinfo(np.int32).max, size=total_contexts)

        # Perform parallel predictions
        predictions = Parallel(n_jobs=n_jobs, backend=self.backend)(
                          delayed(self._predict_contexts)(
                              contexts[starts[i]:starts[i + 1]],
                              is_predict,
                              seeds[starts[i]:starts[i + 1]],
                              starts[i])
                          for i in range(n_jobs))

        # Reduce
        predictions = list(chain.from_iterable(t for t in predictions))

        return predictions if len(predictions) > 1 else predictions[0] 
开发者ID:fidelity,项目名称:mabwiser,代码行数:27,代码来源:base_mab.py

示例11: test_big_indices

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def test_big_indices(self):
        # ravel_multi_index for big indices (issue #7546)
        if np.intp == np.int64:
            arr = ([1, 29], [3, 5], [3, 117], [19, 2],
                   [2379, 1284], [2, 2], [0, 1])
            assert_equal(
                np.ravel_multi_index(arr, (41, 7, 120, 36, 2706, 8, 6)),
                [5627771580, 117259570957])

        # test overflow checking for too big array (issue #7546)
        dummy_arr = ([0],[0])
        half_max = np.iinfo(np.intp).max // 2
        assert_equal(
            np.ravel_multi_index(dummy_arr, (half_max, 2)), [0])
        assert_raises(ValueError,
            np.ravel_multi_index, dummy_arr, (half_max+1, 2))
        assert_equal(
            np.ravel_multi_index(dummy_arr, (half_max, 2), order='F'), [0])
        assert_raises(ValueError,
            np.ravel_multi_index, dummy_arr, (half_max+1, 2), order='F') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_index_tricks.py

示例12: test_allclose

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def test_allclose(self):
        # Tests allclose on arrays
        a = np.random.rand(10)
        b = a + np.random.rand(10) * 1e-8
        assert_(allclose(a, b))
        # Test allclose w/ infs
        a[0] = np.inf
        assert_(not allclose(a, b))
        b[0] = np.inf
        assert_(allclose(a, b))
        # Test allclose w/ masked
        a = masked_array(a)
        a[-1] = masked
        assert_(allclose(a, b, masked_equal=True))
        assert_(not allclose(a, b, masked_equal=False))
        # Test comparison w/ scalar
        a *= 1e-8
        a[0] = 0
        assert_(allclose(a, 0, masked_equal=True))

        # Test that the function works for MIN_INT integer typed arrays
        a = masked_array([np.iinfo(np.int_).min], dtype=np.int_)
        assert_(allclose(a, a)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_core.py

示例13: test_respect_dtype_singleton

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def test_respect_dtype_singleton(self):
        # See gh-7203
        for dt in self.itype:
            lbnd = 0 if dt is np.bool_ else np.iinfo(dt).min
            ubnd = 2 if dt is np.bool_ else np.iinfo(dt).max + 1

            sample = self.rfunc(lbnd, ubnd, dtype=dt)
            assert_equal(sample.dtype, np.dtype(dt))

        for dt in (bool, int, np.long):
            lbnd = 0 if dt is bool else np.iinfo(dt).min
            ubnd = 2 if dt is bool else np.iinfo(dt).max + 1

            # gh-7284: Ensure that we get Python data types
            sample = self.rfunc(lbnd, ubnd, dtype=dt)
            assert_(not hasattr(sample, 'dtype'))
            assert_equal(type(sample), dt) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_random.py

示例14: test_can_cast_values

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def test_can_cast_values(self):
        # gh-5917
        for dt in np.sctypes['int'] + np.sctypes['uint']:
            ii = np.iinfo(dt)
            assert_(np.can_cast(ii.min, dt))
            assert_(np.can_cast(ii.max, dt))
            assert_(not np.can_cast(ii.min - 1, dt))
            assert_(not np.can_cast(ii.max + 1, dt))

        for dt in np.sctypes['float']:
            fi = np.finfo(dt)
            assert_(np.can_cast(fi.min, dt))
            assert_(np.can_cast(fi.max, dt))


# Custom exception class to test exception propagation in fromiter 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_numeric.py

示例15: argmin

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iinfo [as 别名]
def argmin(self, axis=None, skipna=True, *args, **kwargs):
        """
        Returns the indices of the minimum values along an axis.

        See `numpy.ndarray.argmin` for more information on the
        `axis` parameter.

        See Also
        --------
        numpy.ndarray.argmin
        """
        nv.validate_argmin(args, kwargs)
        nv.validate_minmax_axis(axis)

        i8 = self.asi8
        if self.hasnans:
            mask = self._isnan
            if mask.all() or not skipna:
                return -1
            i8 = i8.copy()
            i8[mask] = np.iinfo('int64').max
        return i8.argmin() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:datetimelike.py


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