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


Python numpy.round_方法代码示例

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


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

示例1: test_2d

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def test_2d(self):
        # Tests mr_ on 2D arrays.
        a_1 = np.random.rand(5, 5)
        a_2 = np.random.rand(5, 5)
        m_1 = np.round_(np.random.rand(5, 5), 0)
        m_2 = np.round_(np.random.rand(5, 5), 0)
        b_1 = masked_array(a_1, mask=m_1)
        b_2 = masked_array(a_2, mask=m_2)
        # append columns
        d = mr_['1', b_1, b_2]
        assert_(d.shape == (5, 10))
        assert_array_equal(d[:, :5], b_1)
        assert_array_equal(d[:, 5:], b_2)
        assert_array_equal(d.mask, np.r_['1', m_1, m_2])
        d = mr_[b_1, b_2]
        assert_(d.shape == (10, 5))
        assert_array_equal(d[:5,:], b_1)
        assert_array_equal(d[5:,:], b_2)
        assert_array_equal(d.mask, np.r_[m_1, m_2]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_extras.py

示例2: test_2d

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def test_2d(self):
        # Tests mr_ on 2D arrays.
        a_1 = np.random.rand(5, 5)
        a_2 = np.random.rand(5, 5)
        m_1 = np.round_(np.random.rand(5, 5), 0)
        m_2 = np.round_(np.random.rand(5, 5), 0)
        b_1 = masked_array(a_1, mask=m_1)
        b_2 = masked_array(a_2, mask=m_2)
        # append columns
        d = mr_['1', b_1, b_2]
        self.assertTrue(d.shape == (5, 10))
        assert_array_equal(d[:, :5], b_1)
        assert_array_equal(d[:, 5:], b_2)
        assert_array_equal(d.mask, np.r_['1', m_1, m_2])
        d = mr_[b_1, b_2]
        self.assertTrue(d.shape == (10, 5))
        assert_array_equal(d[:5,:], b_1)
        assert_array_equal(d[5:,:], b_2)
        assert_array_equal(d.mask, np.r_[m_1, m_2]) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:test_extras.py

示例3: test_2d

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def test_2d(self):
        "Tests mr_ on 2D arrays."
        a_1 = rand(5, 5)
        a_2 = rand(5, 5)
        m_1 = np.round_(rand(5, 5), 0)
        m_2 = np.round_(rand(5, 5), 0)
        b_1 = masked_array(a_1, mask=m_1)
        b_2 = masked_array(a_2, mask=m_2)
        d = mr_['1', b_1, b_2]  # append columns
        self.assertTrue(d.shape == (5, 10))
        assert_array_equal(d[:, :5], b_1)
        assert_array_equal(d[:, 5:], b_2)
        assert_array_equal(d.mask, np.r_['1', m_1, m_2])
        d = mr_[b_1, b_2]
        self.assertTrue(d.shape == (10, 5))
        assert_array_equal(d[:5,:], b_1)
        assert_array_equal(d[5:,:], b_2)
        assert_array_equal(d.mask, np.r_[m_1, m_2]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:test_extras.py

示例4: fast_smoothing

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def fast_smoothing(odms, high, low, threshold):
	for i,odm in (enumerate(odms)):
		copy = np.array(odm)
		on = np.where(odm != high)
		for x,y in zip(*on):
			window = odm[x-3:x+4,y-3:y+4] #window
		
			considered =  np.where( abs(window - odm[x,y])< threshold)
			copy[x,y] = np.average(window[considered])


		odms[i] = np.round_(copy)
		
	return odms


# reconvers full odm from occupancy and depth map 
开发者ID:EdwardSmith1884,项目名称:Multi-View-Silhouette-and-Depth-Decomposition-for-High-Resolution-3D-Object-Representation,代码行数:19,代码来源:utils.py

示例5: summary

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def summary(self, decimal=3):
        """Generate the summary information after the corrected risk ratio distribution is
        generated. fit() must be run before this

        Parameters
        -------------
        decimal : int, optional
            Decimal places to display in output. Default is 3
        """
        print('----------------------------------------------------------------------')
        print('Median corrected Risk Ratio: ', np.round(np.median(self.corrected_RR),decimal))
        print('Mean corrected Risk Ratio: ', np.round(np.mean(self.corrected_RR),decimal))
        print('25th & 75th Percentiles: ', np.round_(np.percentile(self.corrected_RR,q=[25, 75]), decimals=decimal))
        print('2.5th & 97.5th Percentiles: ', np.round_(np.percentile(self.corrected_RR,q=[2.5, 97.5]),
                                                        decimals=decimal))
        print('----------------------------------------------------------------------') 
开发者ID:pzivich,项目名称:zEpid,代码行数:18,代码来源:Simple.py

示例6: test_2d

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def test_2d(self):
        # Tests mr_ on 2D arrays.
        a_1 = rand(5, 5)
        a_2 = rand(5, 5)
        m_1 = np.round_(rand(5, 5), 0)
        m_2 = np.round_(rand(5, 5), 0)
        b_1 = masked_array(a_1, mask=m_1)
        b_2 = masked_array(a_2, mask=m_2)
        # append columns
        d = mr_['1', b_1, b_2]
        self.assertTrue(d.shape == (5, 10))
        assert_array_equal(d[:, :5], b_1)
        assert_array_equal(d[:, 5:], b_2)
        assert_array_equal(d.mask, np.r_['1', m_1, m_2])
        d = mr_[b_1, b_2]
        self.assertTrue(d.shape == (10, 5))
        assert_array_equal(d[:5,:], b_1)
        assert_array_equal(d[5:,:], b_2)
        assert_array_equal(d.mask, np.r_[m_1, m_2]) 
开发者ID:pfchai,项目名称:ImageFusion,代码行数:21,代码来源:test_extras.py

示例7: test_assemble_matrixT_returns_expected_output_with_known_input

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def test_assemble_matrixT_returns_expected_output_with_known_input(self):
        """Sends input that has known T matrix, expects the same output"""
        ang_list = [0, 90, -45, +45, 90, 0]
        for ang in ang_list:
            T = clt.assemble_matrixT(ang)
            T = numpy.round_(T, 6)
            if ang == 0:
                expected_T = numpy.array([[ 1,  0,  0],
                                          [ 0,  1,  0],
                                          [ 0,  0,  1]])
            elif ang == 90:
                expected_T = numpy.array([[ 0,  1,  0],
                                          [ 1,  0,  0],
                                          [ 0,  0, -1]])
            elif ang == -45:
                expected_T = numpy.array([[ 0.5,  0.5, -0.5],
                                          [ 0.5,  0.5, -0.5],
                                          [  1,    -1,    0]])
            elif ang == +45:
                expected_T = numpy.array([[ 0.5,  0.5,  0.5],
                                          [ 0.5,  0.5, -0.5],
                                          [  -1,    1,    0]])
            expected_Ti_list = [int(Ti) for Ti in numpy.nditer(expected_T)]
            returned_Ti_list = [int(Ti) for Ti in numpy.nditer(T)]
            self.assertTrue(expected_Ti_list == returned_Ti_list) 
开发者ID:joaopbernhardt,项目名称:lamipy,代码行数:27,代码来源:tests.py

示例8: fix_top

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def fix_top(A):
    """
    Takes a symmetric binary matrix with ones along the diagonal
    and returns the permutation matrix P such that the [1:t,1:t]
    submatrix of P A P is invertible

    """
    if A.shape == (1, 1):
        return _np.eye(1, dtype='int')

    t = len(A)

    found_B = False
    for ind in range(t):
        aa, P = permute_top(A, ind)
        B = _np.round_(aa[1:, 1:])

        if detmod2(B) == 0:
            continue
        else:
            found_B = True
            break

    # Todo : put a more meaningful fail message here #
    assert(found_B), "Algorithm failed!"

    return P 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:29,代码来源:matrixmod2.py

示例9: test_learning_2x2_grid_world

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def test_learning_2x2_grid_world(self):
        """
        Tests if apex can learn a simple environment using a single worker, thus replicating
        dqn.
        """
        env_spec = dict(
            type="grid-world",
            world="2x2",
            save_mode=False
        )
        agent_config = config_from_path("configs/apex_agent_for_2x2_gridworld.json")
        executor = ApexExecutor(
            environment_spec=env_spec,
            agent_config=agent_config,
        )
        # Define executor, test assembly.
        print("Successfully created executor.")

        # Executes actual workload.
        result = executor.execute_workload(workload=dict(
            num_timesteps=5000, report_interval=100, report_interval_min_seconds=1)
        )
        full_worker_stats = executor.result_by_worker()
        print("All finished episode rewards")
        print(full_worker_stats["episode_rewards"])

        print("STATES:\n{}".format(executor.local_agent.last_q_table["states"]))
        print("\n\nQ(s,a)-VALUES:\n{}".format(np.round_(executor.local_agent.last_q_table["q_values"], decimals=2)))

        # Check q-table for correct values.
        expected_q_values_per_state = {
            (1.0, 0, 0, 0): (-1, -5, 0, -1),
            (0, 1.0, 0, 0): (-1, 1, 0, 0)
        }
        for state, q_values in zip(
                executor.local_agent.last_q_table["states"], executor.local_agent.last_q_table["q_values"]
        ):
            state, q_values = tuple(state), tuple(q_values)
            assert state in expected_q_values_per_state, \
                "ERROR: state '{}' not expected in q-table as it's a terminal state!".format(state)
            recursive_assert_almost_equal(q_values, expected_q_values_per_state[state], decimals=0) 
开发者ID:rlgraph,项目名称:rlgraph,代码行数:43,代码来源:test_apex_executor.py

示例10: get_dataloader

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def get_dataloader(datapath, args, num_templates=25,
                   template_file="templates.json", img_transforms=None,
                   train=True, split="train"):
    template_file = osp.join("datasets", template_file)

    if osp.exists(template_file):
        templates = json.load(open(template_file))

    else:
        # Cluster the bounding boxes to get the templates
        dataset = WIDERFace(osp.expanduser(args.traindata), [])
        clustering = compute_kmedoids(dataset.get_all_bboxes(), 1, indices=num_templates,
                                      option='pyclustering', max_clusters=num_templates)

        print("Canonical bounding boxes computed")
        templates = clustering[num_templates]['medoids'].tolist()

        # record templates
        json.dump(templates, open(template_file, "w"))

    templates = np.round_(np.array(templates), decimals=8)

    data_loader = data.DataLoader(WIDERFace(osp.expanduser(datapath), templates,
                                            train=train, split=split, img_transforms=img_transforms,
                                            dataset_root=osp.expanduser(args.dataset_root),
                                            debug=args.debug),
                                  batch_size=args.batch_size, shuffle=train,
                                  num_workers=args.workers, pin_memory=True)

    return data_loader, templates 
开发者ID:varunagrawal,项目名称:tiny-faces-pytorch,代码行数:32,代码来源:__init__.py

示例11: recover_depths

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def recover_depths(preds, ups, high, dis): 
	preds =  np.round_(preds*dis).reshape((-1,high,high)) 
	ups = np.array(ups).reshape((-1,high,high))

	for pred, up, i in zip(preds, ups, range(preds.shape[0])):
		pred = np.array(pred)
		pred  = up + pred # add to upsampled low resolution odm
		off = np.where(pred > high)  # set values which predict to high to be unoccupited -> 0        
		pred[off] = high-1 
		preds[i] = pred
	return preds

# compute complete occupancy map, basically thresholds the probability outputs 
开发者ID:EdwardSmith1884,项目名称:Multi-View-Silhouette-and-Depth-Decomposition-for-High-Resolution-3D-Object-Representation,代码行数:15,代码来源:utils.py

示例12: get_section

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def get_section(
        self,
        start_polar: Optional[Tuple[float, float]] = None,
        end_polar: Optional[Tuple[float, float]] = None,
        start_cart: Optional[Tuple[float, float]] = None,
        end_cart: Optional[Tuple[float, float]] = None,
        spacing: int = 500,
    ) -> Dataset:
        r"""
        Get cross-section data from input points

        Args:
            start_polar (tuple): polar coordinates of start point i.e.(distance, azimuth)

            end_polar (tuple): polar coordinates of end point i.e.(distance, azimuth)

            start_cart (tuple): geographic coordinates of start point i.e.(longitude, latitude)

            end_cart (tuple): geographic coordinates of end point i.e.(longitude, latitude)

        Returns:
            xarray.Dataset: Cross-section data
        """
        if start_polar and end_polar:
            stlat = self.rl[0].stp["lat"]
            stlon = self.rl[0].stp["lon"]
            stp = np.round_(
                get_coordinate(
                    start_polar[0], start_polar[1] * deg2rad, 0, stlon, stlat
                ),
                2,
            )
            enp = np.round_(
                get_coordinate(end_polar[0], end_polar[1] * deg2rad, 0, stlon, stlat), 2
            )
        elif start_cart and end_cart:
            stp = start_cart
            enp = end_cart
        else:
            raise RadarCalculationError("Invalid input")
        return self._get_section(stp, enp, spacing) 
开发者ID:CyanideCN,项目名称:PyCINRAD,代码行数:43,代码来源:calc.py

示例13: _process_grid

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def _process_grid(self, x_step: Number_T, y_step: Number_T) -> Tuple[np.ndarray]:
        x_lower = np.round_(self.lon_ravel.min(), 2)
        x_upper = np.round_(self.lon_ravel.max(), 2)
        y_lower = np.round_(self.lat_ravel.min(), 2)
        y_upper = np.round_(self.lat_ravel.max(), 2)
        x_grid = np.arange(x_lower, x_upper + x_step, x_step)
        y_grid = np.arange(y_lower, y_upper + x_step, x_step)
        return np.meshgrid(x_grid, y_grid) 
开发者ID:CyanideCN,项目名称:PyCINRAD,代码行数:10,代码来源:calc.py

示例14: test_round_

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def test_round_(self):
        self.check(np.round_) 
开发者ID:holzschu,项目名称:Carnets,代码行数:4,代码来源:test_quantity_non_ufuncs.py

示例15: get_orthogonal_grid_edges

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import round_ [as 别名]
def get_orthogonal_grid_edges(pix_x, pix_y, scale_aspect=True):
    """calculate the bin edges of the slanted, orthogonal pixel grid to
    resample the pixel signals with np.histogramdd right after.

    Parameters
    ----------
    pix_x, pix_y : 1D numpy arrays
        the list of x and y coordinates of the slanted, orthogonal pixel grid
        units should be in meters, and stripped off
    scale_aspect : boolean (default: True)
        if True, rescales the x-coordinates to create square pixels
        (instead of rectangular ones)

    Returns
    --------
    x_edges, y_edges : 1D numpy arrays
        the bin edges for the slanted, orthogonal pixel grid
    x_scale : float
        factor by which the x-coordinates have been scaled
    """

    # finding the size of the square patches

    d_x = 99
    d_y = 99
    x_base = pix_x[0]
    y_base = pix_y[0]
    for x, y in zip(pix_x, pix_y):
        if abs(y - y_base) < abs(x - x_base):
            d_x = min(d_x, abs(x - x_base))
        if abs(y - y_base) > abs(x - x_base):
            d_y = min(d_y, abs(y - y_base))

    # for x, y in zip(pix_x, pix_y):
    #    if abs(y - y_base) > abs(x - x_base):
    #        d_y = min(d_y, abs(y - y_base))

    x_scale = 1
    if scale_aspect:
        x_scale = d_y / d_x
        pix_x *= x_scale
        d_x = d_y

    # with the maximal extension of the axes and the size of the pixels,
    # determine the number of bins in each direction
    n_bins_x = int(np.round_(np.abs(np.max(pix_x) - np.min(pix_x)) / d_x) + 2)
    n_bins_y = int(np.round_(np.abs(np.max(pix_y) - np.min(pix_y)) / d_y) + 2)
    x_edges = np.linspace(pix_x.min(), pix_x.max(), n_bins_x)
    y_edges = np.linspace(pix_y.min(), pix_y.max(), n_bins_y)

    return (x_edges, y_edges, x_scale) 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:53,代码来源:geometry_converter_hex.py


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