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


Python numpy.printoptions方法代碼示例

本文整理匯總了Python中numpy.printoptions方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.printoptions方法的具體用法?Python numpy.printoptions怎麽用?Python numpy.printoptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.printoptions方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _to_str

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def _to_str(self, representation=False):
        if build_mode().is_build_mode or len(self._executed_sessions) == 0:
            # in build mode, or not executed, just return representation
            if representation:
                return 'Tensor <op={}, shape={}, key={}'.format(self._op.__class__.__name__,
                                                                self._shape,
                                                                self._key)
            else:
                return 'Tensor(op={}, shape={})'.format(self._op.__class__.__name__,
                                                        self._shape)
        else:
            print_options = np.get_printoptions()
            threshold = print_options['threshold']

            corner_data = fetch_corner_data(self, session=self._executed_sessions[-1])
            # if less than default threshold, just set it as default,
            # if not, set to corner_data.size - 1 make sure ... exists in repr
            threshold = threshold if self.size <= threshold else corner_data.size - 1
            with np.printoptions(threshold=threshold):
                corner_str = repr(corner_data) if representation else str(corner_data)
            return corner_str 
開發者ID:mars-project,項目名稱:mars,代碼行數:23,代碼來源:core.py

示例2: testFetchTensorCornerData

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def testFetchTensorCornerData(self):
        sess = new_session()
        print_options = np.get_printoptions()

        # make sure numpy default option
        self.assertEqual(print_options['edgeitems'], 3)
        self.assertEqual(print_options['threshold'], 1000)

        size = 12
        for i in (2, 4, size - 3, size, size + 3):
            arr = np.random.rand(i, i, i)
            t = mt.tensor(arr, chunk_size=size // 2)
            sess.run(t, fetch=False)

            corner_data = fetch_corner_data(t, session=sess)
            corner_threshold = 1000 if t.size < 1000 else corner_data.size - 1
            with np.printoptions(threshold=corner_threshold, suppress=True):
                # when we repr corner data, we need to limit threshold that
                # it's exactly less than the size
                repr_corner_data = repr(corner_data)
            with np.printoptions(suppress=True):
                repr_result = repr(arr)
            self.assertEqual(repr_corner_data, repr_result,
                             'failed when size == {}'.format(i)) 
開發者ID:mars-project,項目名稱:mars,代碼行數:26,代碼來源:test_utils.py

示例3: __repr__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def __repr__(self):
        with numpy.printoptions(linewidth=100, threshold=200, edgeitems=9):
            string = (
                "reward: %s\n"
                "time: %s\n"
                "observ: %s\n"
                "state: %s\n"
                "id: %s"
                % (
                    self.rewards[0],
                    self.times[0],
                    self.observs[0].flatten(),
                    self.states[0].flatten(),
                    self.id_walkers[0],
                )
            )
            return string 
開發者ID:FragileTech,項目名稱:fragile,代碼行數:19,代碼來源:states.py

示例4: printoptions

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def printoptions(*args, **kwargs):
    """Context manager for setting print options.

    Set print options for the scope of the `with` block, and restore the old
    options at the end. See `set_printoptions` for the full description of
    available options.

    Examples
    --------

    >>> with np.printoptions(precision=2):
    ...     print(np.array([2.0])) / 3
    [0.67]

    The `as`-clause of the `with`-statement gives the current print options:

    >>> with np.printoptions(precision=2) as opts:
    ...      assert_equal(opts, np.get_printoptions())

    See Also
    --------
    set_printoptions, get_printoptions

    """
    opts = np.get_printoptions()
    try:
        np.set_printoptions(*args, **kwargs)
        yield np.get_printoptions()
    finally:
        np.set_printoptions(**opts) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:32,代碼來源:arrayprint.py

示例5: test_0d_arrays

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def test_0d_arrays(self):
        unicode = type(u'')

        assert_equal(unicode(np.array(u'café', '<U4')), u'café')

        if sys.version_info[0] >= 3:
            assert_equal(repr(np.array('café', '<U4')),
                         "array('café', dtype='<U4')")
        else:
            assert_equal(repr(np.array(u'café', '<U4')),
                         "array(u'caf\\xe9', dtype='<U4')")
        assert_equal(str(np.array('test', np.str_)), 'test')

        a = np.zeros(1, dtype=[('a', '<i4', (3,))])
        assert_equal(str(a[0]), '([0, 0, 0],)')

        assert_equal(repr(np.datetime64('2005-02-25')[...]),
                     "array('2005-02-25', dtype='datetime64[D]')")

        assert_equal(repr(np.timedelta64('10', 'Y')[...]),
                     "array(10, dtype='timedelta64[Y]')")

        # repr of 0d arrays is affected by printoptions
        x = np.array(1)
        np.set_printoptions(formatter={'all':lambda x: "test"})
        assert_equal(repr(x), "array(test)")
        # str is unaffected
        assert_equal(str(x), "1")

        # check `style` arg raises
        assert_warns(DeprecationWarning, np.array2string,
                                         np.array(1.), style=repr)
        # but not in legacy mode
        np.array2string(np.array(1.), style=repr, legacy='1.13')
        # gh-10934 style was broken in legacy mode, check it works
        np.array2string(np.array(1.), legacy='1.13') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:38,代碼來源:test_arrayprint.py

示例6: test_ctx_mgr

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def test_ctx_mgr(self):
        # test that context manager actuall works
        with np.printoptions(precision=2):
            s = str(np.array([2.0]) / 3)
        assert_equal(s, '[0.67]') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_arrayprint.py

示例7: test_ctx_mgr_restores

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def test_ctx_mgr_restores(self):
        # test that print options are actually restrored
        opts = np.get_printoptions()
        with np.printoptions(precision=opts['precision'] - 1,
                             linewidth=opts['linewidth'] - 4):
            pass
        assert_equal(np.get_printoptions(), opts) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_arrayprint.py

示例8: test_ctx_mgr_exceptions

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def test_ctx_mgr_exceptions(self):
        # test that print options are restored even if an exception is raised
        opts = np.get_printoptions()
        try:
            with np.printoptions(precision=2, linewidth=11):
                raise ValueError
        except ValueError:
            pass
        assert_equal(np.get_printoptions(), opts) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_arrayprint.py

示例9: __repr__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def __repr__(self):
        with numpy.printoptions(linewidth=100, threshold=200, edgeitems=9):
            init_actions = self.internal_swarm.walkers.states.init_actions.flatten()
            y = numpy.bincount(init_actions.astype(int))
            ii = numpy.nonzero(y)[0]
            string = str(self.root_walker)
            string += "\n Init actions [action, count]: \n%s" % numpy.vstack((ii, y[ii])).T
            return string 
開發者ID:FragileTech,項目名稱:fragile,代碼行數:10,代碼來源:step_swarm.py

示例10: __repr__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import printoptions [as 別名]
def __repr__(self) -> str:
        """Print all the data involved in the current run of the algorithm."""
        with numpy.printoptions(linewidth=100, threshold=200, edgeitems=9):
            try:
                text = self._print_stats()
                text += "Walkers States: {}\n".format(self._repr_state(self._states))
                text += "Environment States: {}\n".format(self._repr_state(self._env_states))
                text += "Model States: {}\n".format(self._repr_state(self._model_states))
                return text
            except Exception:
                return super(SimpleWalkers, self).__repr__() 
開發者ID:FragileTech,項目名稱:fragile,代碼行數:13,代碼來源:walkers.py


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