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


Python numpy.modf方法代码示例

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


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

示例1: testMultipleOutputExecute

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def testMultipleOutputExecute(self):
        with option_context({'eager_mode': True}):
            data = np.random.random((5, 9))

            arr1 = mt.tensor(data.copy(), chunk_size=3)
            result = mt.modf(arr1)
            expected = np.modf(data)

            np.testing.assert_array_equal(result[0].fetch(), expected[0])
            np.testing.assert_array_equal(result[1].fetch(), expected[1])

            arr3 = mt.tensor(data.copy(), chunk_size=3)
            result1, result2, result3 = mt.split(arr3, 3, axis=1)
            expected = np.split(data, 3, axis=1)

            np.testing.assert_array_equal(result1.fetch(), expected[0])
            np.testing.assert_array_equal(result2.fetch(), expected[1])
            np.testing.assert_array_equal(result3.fetch(), expected[2]) 
开发者ID:mars-project,项目名称:mars,代码行数:20,代码来源:test_eager_mode.py

示例2: convert_date

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def convert_date(config, array):

    """ Convert date from years since 1970 to year """

    date_band = config['general']['date_band'] - 1
    if len(array.shape) == 3:
        array[date_band,:,:][array[date_band,:,:] > 0] += 1970
        doys = np.modf(array[date_band,:,:])[0]
        doys = ((doys * 365).astype(int)).astype(np.str)
        array[date_band,:,:] = np.core.defchararray.add(
	    		       array[date_band,:,:].astype(np.int).
			       astype(np.str), doys)
    else:
        array[array > 0] += 1970
        doys = np.modf(array)[0]
        doys = ((doys * 365).astype(int)).astype(np.str)
        array = np.core.defchararray.add(
	        array.astype(np.int).
	        astype(np.str), doys)
    return array 
开发者ID:bullocke,项目名称:coded,代码行数:22,代码来源:postprocess_utils.py

示例3: _round_frac

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def _round_frac(x, precision):
    """
    Round the fractional part of the given number
    """
    if not np.isfinite(x) or x == 0:
        return x
    else:
        frac, whole = np.modf(x)
        if whole == 0:
            digits = -int(np.floor(np.log10(abs(frac)))) - 1 + precision
        else:
            digits = precision
        return np.around(x, digits) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:tile.py

示例4: execute

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def execute(cls, ctx, op):
        inputs, device_id, xp = as_same_device(
            [ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True)

        with device(device_id):
            kw = {'casting': op.casting}

            inputs_iter = iter(inputs)
            input = next(inputs_iter)
            if op.out1 is not None:
                out1 = next(inputs_iter)
            else:
                out1 = None
            if op.out2 is not None:
                out2 = next(inputs_iter)
            else:
                out2 = None
            if op.where is not None:
                where = kw['where'] = next(inputs_iter)
            else:
                where = None
            kw['order'] = op.order

            try:
                args = [input]
                if out1 is not None:
                    args.append(out1.copy())
                if out2 is not None:
                    args.append(out2.copy())
                y1, y2 = xp.modf(*args, **kw)
            except TypeError:
                if where is None:
                    raise
                y1, y2 = xp.modf(input)
                y1, y2 = xp.where(where, y1, out1), xp.where(where, y2, out2)

            for c, res in zip(op.outputs, (y1, y2)):
                ctx[c.key] = res 
开发者ID:mars-project,项目名称:mars,代码行数:40,代码来源:modf.py

示例5: testModfExecution

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def testModfExecution(self):
        data1 = np.random.random((5, 9))

        arr1 = tensor(data1.copy(), chunk_size=3)

        o1, o2 = modf(arr1)
        o = o1 + o2

        res = self.executor.execute_tensor(o, concat=True)[0]
        expected = sum(np.modf(data1))
        self.assertTrue(np.allclose(res, expected))

        o1, o2 = modf([0, 3.5])
        o = o1 + o2

        res = self.executor.execute_tensor(o, concat=True)[0]
        expected = sum(np.modf([0, 3.5]))
        self.assertTrue(np.allclose(res, expected))

        arr1 = tensor(data1.copy(), chunk_size=3)
        o1 = zeros(data1.shape, chunk_size=3)
        o2 = zeros(data1.shape, chunk_size=3)
        modf(arr1, o1, o2)
        o = o1 + o2

        res = self.executor.execute_tensor(o, concat=True)[0]
        expected = sum(np.modf(data1))
        self.assertTrue(np.allclose(res, expected))

        data1 = sps.random(5, 9, density=.1)

        arr1 = tensor(data1.copy(), chunk_size=3)

        o1, o2 = modf(arr1)
        o = o1 + o2

        res = self.executor.execute_tensor(o, concat=True)[0]
        expected = sum(np.modf(data1.toarray()))
        np.testing.assert_equal(res.toarray(), expected) 
开发者ID:mars-project,项目名称:mars,代码行数:41,代码来源:test_arithmetic_execution.py

示例6: testModfOrderExecution

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def testModfOrderExecution(self):
        data1 = np.random.random((5, 9))
        t = tensor(data1, chunk_size=3)

        o1, o2 = modf(t, order='F')
        res1, res2 = self.executor.execute_tileables([o1, o2])
        expected1, expected2 = np.modf(data1, order='F')
        np.testing.assert_allclose(res1, expected1)
        self.assertTrue(res1.flags['F_CONTIGUOUS'])
        self.assertFalse(res1.flags['C_CONTIGUOUS'])
        np.testing.assert_allclose(res2, expected2)
        self.assertTrue(res2.flags['F_CONTIGUOUS'])
        self.assertFalse(res2.flags['C_CONTIGUOUS']) 
开发者ID:mars-project,项目名称:mars,代码行数:15,代码来源:test_arithmetic_execution.py

示例7: common_asserts_for_test_data

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def common_asserts_for_test_data(self, data):
    """See base class."""
    frac_x, _ = np.modf(data.x)
    frac_encoded_x, _ = np.modf(data.encoded_x[self._ENCODED_VALUES_KEY])
    # The decimal places should be the same.
    self.assertAllClose(
        frac_x,
        frac_encoded_x,
        rtol=test_utils.DEFAULT_RTOL,
        atol=test_utils.DEFAULT_ATOL) 
开发者ID:tensorflow,项目名称:model-optimization,代码行数:12,代码来源:test_utils_test.py

示例8: test_ufunc_override_out

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def test_ufunc_override_out(self):
        # 2016-01-29: NUMPY_UFUNC_DISABLED
        return

        class A(object):
            def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
                return kwargs

        class B(object):
            def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
                return kwargs

        a = A()
        b = B()
        res0 = np.multiply(a, b, 'out_arg')
        res1 = np.multiply(a, b, out='out_arg')
        res2 = np.multiply(2, b, 'out_arg')
        res3 = np.multiply(3, b, out='out_arg')
        res4 = np.multiply(a, 4, 'out_arg')
        res5 = np.multiply(a, 5, out='out_arg')

        assert_equal(res0['out'], 'out_arg')
        assert_equal(res1['out'], 'out_arg')
        assert_equal(res2['out'], 'out_arg')
        assert_equal(res3['out'], 'out_arg')
        assert_equal(res4['out'], 'out_arg')
        assert_equal(res5['out'], 'out_arg')

        # ufuncs with multiple output modf and frexp.
        res6 = np.modf(a, 'out0', 'out1')
        res7 = np.frexp(a, 'out0', 'out1')
        assert_equal(res6['out'][0], 'out0')
        assert_equal(res6['out'][1], 'out1')
        assert_equal(res7['out'][0], 'out0')
        assert_equal(res7['out'][1], 'out1') 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:37,代码来源:test_umath.py

示例9: _format_label

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def _format_label(x, precision=3):
    fmt_str = '%%.%dg' % precision
    if np.isinf(x):
        return str(x)
    elif com.is_float(x):
        frac, whole = np.modf(x)
        sgn = '-' if x < 0 else ''
        whole = abs(whole)
        if frac != 0.0:
            val = fmt_str % frac

            # rounded up or down
            if '.' not in val:
                if x < 0:
                    return '%d' % (-whole - 1)
                else:
                    return '%d' % (whole + 1)

            if 'e' in val:
                return _trim_zeros(fmt_str % x)
            else:
                val = _trim_zeros(val)
                if '.' in val:
                    return sgn + '.'.join(('%d' % whole, val.split('.')[1]))
                else:  # pragma: no cover
                    return sgn + '.'.join(('%d' % whole, val))
        else:
            return sgn + '%0.f' % whole
    else:
        return str(x) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:32,代码来源:tile.py

示例10: evaluate

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def evaluate(self, ts):
        """Evaluates the signal at the given times.

        ts: float array of times
        
        returns: float wave array
        """
        ts = np.asarray(ts)
        cycles = self.freq * ts + self.offset / PI2
        frac, _ = np.modf(cycles)
        ys = self.amp * np.sign(unbias(frac))
        return ys 
开发者ID:Notabela,项目名称:Lie_to_me,代码行数:14,代码来源:thinkdsp.py

示例11: test_timeseries_class

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def test_timeseries_class(model, start_time, series):
    inseries = series[0]

    parameterset = model.parameters
    parameter = parameterset.timeseries(
        "Parameter",
        "",
        create_time_points(
            start_time, 24 * 3600, len(inseries), ParameterType.AVERAGE_TIMESERIES
        ),
        timeseries_type="average",
    )
    parameter.values = inseries

    assert parameter.values.shape == inseries.shape
    assert parameter.values.nbytes == inseries.nbytes
    assert parameter.values.dtype == inseries.dtype
    assert parameter.values.ndim == 1
    assert np.all(parameter.values[:] == parameter.values[:])
    assert str(parameter.values) == "timeseries({})".format(repr(inseries))

    np.testing.assert_allclose(np.add(parameter.values, inseries), 2 * inseries)
    assert np.sum(parameter.values) == np.sum(inseries)

    out = np.empty_like(inseries, dtype=float)
    np.sin(parameter.values, out=out)
    np.testing.assert_allclose(out, np.sin(inseries))

    out0 = np.empty_like(inseries, dtype=float)
    out1 = np.empty_like(inseries, dtype=float)
    np.modf(parameter.values, out=(out0, out1))
    out = np.modf(inseries)
    np.testing.assert_equal(out[0], out0)
    np.testing.assert_equal(out[1], out1) 
开发者ID:openscm,项目名称:openscm,代码行数:36,代码来源:test_core.py

示例12: transformMarkerImage

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def transformMarkerImage(self, marker_pixel_pos, marker_yaw, maker_scale):
        """

        :param marker_pixel_pos:
        :param marker_yaw:
        :param maker_scale:
        :return:
        """
        self.marker_yaw = marker_yaw
        self.marker_pixel_pos = np.float32(marker_pixel_pos).reshape((2, ))
        self.maker_scale = maker_scale
        self.M_marker_with_margin = cv2.getRotationMatrix2D((self.marker_image_with_margin.shape[1] / 2,
                                                             self.marker_image_with_margin.shape[0] / 2),
                                                            self.marker_yaw * 180 / np.pi, self.maker_scale)
        self.marker_pixel_pos_fraction, self.marker_pixel_pos_interger = np.modf(self.marker_pixel_pos)

        self.marker_pixel_pos_interger = self.marker_pixel_pos_interger.astype(np.int)
        self.M_marker_with_margin[0, 2] += \
            self.marker_pixel_pos_fraction[1] + self.roi_half_length - self.marker_image_with_margin.shape[0] / 2
        self.M_marker_with_margin[1, 2] += \
            self.marker_pixel_pos_fraction[0] + self.roi_half_length - self.marker_image_with_margin.shape[1] / 2

        self.marker_image_transformed = cv2.warpAffine(self.marker_image_with_margin, self.M_marker_with_margin,
                                                       (self.roi_length, self.roi_length))
        
        self.marker_weight_transformed = cv2.warpAffine(self.marker_weight, self.M_marker_with_margin,
                                                        (self.roi_length, self.roi_length))  # white: Marker part

        self.bg_weight = 1.0 - self.marker_weight_transformed  # white: origin image part 
开发者ID:araffin,项目名称:robotics-rl-srl,代码行数:31,代码来源:marker_render.py

示例13: test_ufunc_override_out

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def test_ufunc_override_out(self):
        class A(object):
            def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
                return kwargs


        class B(object):
            def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
                return kwargs

        a = A()
        b = B()
        res0 = np.multiply(a, b, 'out_arg')
        res1 = np.multiply(a, b, out='out_arg')
        res2 = np.multiply(2, b, 'out_arg')
        res3 = np.multiply(3, b, out='out_arg')
        res4 = np.multiply(a, 4, 'out_arg')
        res5 = np.multiply(a, 5, out='out_arg')

        assert_equal(res0['out'], 'out_arg')
        assert_equal(res1['out'], 'out_arg')
        assert_equal(res2['out'], 'out_arg')
        assert_equal(res3['out'], 'out_arg')
        assert_equal(res4['out'], 'out_arg')
        assert_equal(res5['out'], 'out_arg')

        # ufuncs with multiple output modf and frexp.
        res6 = np.modf(a, 'out0', 'out1')
        res7 = np.frexp(a, 'out0', 'out1')
        assert_equal(res6['out'][0], 'out0')
        assert_equal(res6['out'][1], 'out1')
        assert_equal(res7['out'][0], 'out0')
        assert_equal(res7['out'][1], 'out1') 
开发者ID:pfchai,项目名称:ImageFusion,代码行数:35,代码来源:test_umath.py

示例14: main

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def main(self, input_rings, output_rings):
        """Generate a histogram from the input ring data
        @param[in] input_rings List with first ring containing
            data of interest. Must terminate before histogram
            is generated.
        @param[out] output_rings First ring in this list
            will contain the output histogram"""
        histogram = np.reshape(
            np.zeros(self.bins).astype(np.float32),
            (1, self.bins))
        tstart = None
        for span in self.iterate_ring_read(input_rings[0]):
            nchans = self.data_settings['frame_shape'][0]
            if tstart is None:
                tstart = self.data_settings['tstart']
            frequency = self.data_settings['fch1']
            for chan in range(nchans):
                modified_tstart = tstart - self.calculate_delay(
                    frequency,
                    self.data_settings['fch1'])
                frequency -= self.data_settings['foff']
                sort_indices = np.argsort(
                    self.calculate_bin_indices(
                        modified_tstart, self.data_settings['tsamp'],
                        span.data.shape[1] / nchans))
                sorted_data = span.data[0][chan::nchans][sort_indices]
                extra_elements = np.round(self.bins * (1 - np.modf(
                    float(span.data.shape[1] / nchans) / self.bins)[0])).astype(int)
                sorted_data = insert_zeros_evenly(sorted_data, extra_elements)
                histogram += np.sum(
                    sorted_data.reshape(self.bins, -1), 1).astype(np.float32)
            tstart += (self.data_settings['tsamp'] *
                       self.gulp_size * 8 / self.data_settings['nbit'] / nchans)
        self.out_gulp_size = self.bins * 4
        out_span_generator = self.iterate_ring_write(output_rings[0])
        out_span = out_span_generator.next()
        bifrost.memory.memcpy(
            out_span.data_view(dtype=np.float32),
            histogram) 
开发者ID:ledatelescope,项目名称:bifrost,代码行数:41,代码来源:block.py

示例15: subpixel_indices

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import modf [as 别名]
def subpixel_indices(position, subsampling):
    """
    Convert decimal points to indices, given a subsampling factor.

    This discards the integer part of the position and uses only the decimal
    place, and converts this to a subpixel position depending on the
    subsampling specified. The center of a pixel corresponds to an integer
    position.

    Parameters
    ----------
    position : `~numpy.ndarray` or array_like
        Positions in pixels.
    subsampling : int
        Subsampling factor per pixel.

    Returns
    -------
    indices : `~numpy.ndarray`
        The integer subpixel indices corresponding to the input positions.

    Examples
    --------

    If no subsampling is used, then the subpixel indices returned are always 0:

    >>> from astropy.nddata.utils import subpixel_indices
    >>> subpixel_indices([1.2, 3.4, 5.6], 1)  # doctest: +FLOAT_CMP
    array([0., 0., 0.])

    If instead we use a subsampling of 2, we see that for the two first values
    (1.1 and 3.4) the subpixel position is 1, while for 5.6 it is 0. This is
    because the values of 1, 3, and 6 lie in the center of pixels, and 1.1 and
    3.4 lie in the left part of the pixels and 5.6 lies in the right part.

    >>> subpixel_indices([1.2, 3.4, 5.5], 2)  # doctest: +FLOAT_CMP
    array([1., 1., 0.])
    """
    # Get decimal points
    fractions = np.modf(np.asanyarray(position) + 0.5)[0]
    return np.floor(fractions * subsampling) 
开发者ID:holzschu,项目名称:Carnets,代码行数:43,代码来源:utils.py


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