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


Python numpy.get_printoptions方法代碼示例

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


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

示例1: test_str_repr_legacy

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def test_str_repr_legacy(self):
        oldopts = np.get_printoptions()
        np.set_printoptions(legacy='1.13')
        try:
            a = array([0, 1, 2], mask=[False, True, False])
            assert_equal(str(a), '[0 -- 2]')
            assert_equal(repr(a), 'masked_array(data = [0 -- 2],\n'
                                  '             mask = [False  True False],\n'
                                  '       fill_value = 999999)\n')

            a = np.ma.arange(2000)
            a[1:50] = np.ma.masked
            assert_equal(
                repr(a),
                'masked_array(data = [0 -- -- ..., 1997 1998 1999],\n'
                '             mask = [False  True  True ..., False False False],\n'
                '       fill_value = 999999)\n'
            )
        finally:
            np.set_printoptions(**oldopts) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:test_core.py

示例2: _to_str

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_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

示例3: testFetchTensorCornerData

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_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

示例4: after_run

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def after_run(self, run_context, run_values):
    _ = run_context
    if self._should_trigger:
      original = np.get_printoptions()
      np.set_printoptions(suppress=True)
      elapsed_secs, _ = self._timer.update_last_triggered_step(self._iter_count)
      if self._formatter:
        logging.info(self._formatter(run_values.results))
      else:
        stats = []
        for tag in self._tag_order:
          stats.append("%s = %s" % (tag, run_values.results[tag]))
        if elapsed_secs is not None:
          logging.info("%s (%.3f sec)", ", ".join(stats), elapsed_secs)
        else:
          logging.info("%s", ", ".join(stats))
      np.set_printoptions(**original)
    self._iter_count += 1 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:basic_session_run_hooks.py

示例5: pformat

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def pformat(obj, indent=0, depth=3):
    if 'numpy' in sys.modules:
        import numpy as np
        print_options = np.get_printoptions()
        np.set_printoptions(precision=6, threshold=64, edgeitems=1)
    else:
        print_options = None
    out = pprint.pformat(obj, depth=depth, indent=indent)
    if print_options:
        np.set_printoptions(**print_options)
    return out


###############################################################################
# class `Logger`
############################################################################### 
開發者ID:flennerhag,項目名稱:mlens,代碼行數:18,代碼來源:logger.py

示例6: np_print_options

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def np_print_options(*args, **kwargs):
    """
    Locally modify print behavior.

    Usage:
    ```
    x = np.random.random(10)
    with printoptions(precision=3, suppress=True):
        print(x)
        # [ 0.073  0.461  0.689  0.754  0.624  0.901  0.049  0.582  0.557  0.348]
    ```

    http://stackoverflow.com/questions/2891790/how-to-pretty-printing-a-numpy-array-without-scientific-notation-and-with-given
    :param args:
    :param kwargs:
    :return:
    """
    original = np.get_printoptions()
    np.set_printoptions(*args, **kwargs)
    yield
    np.set_printoptions(**original)


# TODO(vpong): Test this 
開發者ID:snasiriany,項目名稱:leap,代碼行數:26,代碼來源:np_util.py

示例7: test_matrix_2d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def test_matrix_2d(self):
        thr = np.get_printoptions()["threshold"]
        lw = np.get_printoptions()["linewidth"]
        np.set_printoptions(threshold=np.inf)
        np.set_printoptions(linewidth=500)
        x, y = [np.linspace(0, 4, 5)] * 2
        X, Y = np.meshgrid(x, y, indexing='ij')
        laplace = FinDiff(0, x[1]-x[0], 2) + FinDiff(0, y[1]-y[0], 2)
        #d = FinDiff(1, y[1]-y[0], 2)
        u = X**2 + Y**2

        mat = laplace.matrix(u.shape)

        np.testing.assert_array_almost_equal(4 * np.ones_like(X).reshape(-1), mat.dot(u.reshape(-1)))

        np.set_printoptions(threshold=thr)
        np.set_printoptions(linewidth=lw) 
開發者ID:maroba,項目名稱:findiff,代碼行數:19,代碼來源:test_findiff.py

示例8: plot

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def plot(arr, max_val=None):
    if max_val is None:
        max_arr = arr
        max_val = max(abs(np.max(max_arr)), abs(np.min(max_arr)))

    opts = np.get_printoptions()
    np.set_printoptions(edgeitems=500)
    fig = np.array2string(arr,
                          formatter={
                              'float_kind': lambda x: visual(x, max_val),
                              'int_kind': lambda x: visual(x, max_val)},
                          max_line_width=5000
                          )
    np.set_printoptions(**opts)

    return fig 
開發者ID:yikangshen,項目名稱:Ordered-Memory,代碼行數:18,代碼來源:hinton.py

示例9: plot

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def plot(arr, max_val=None):
    if max_val is None:
        max_arr = arr
        max_val = max(abs(np.max(max_arr)), abs(np.min(max_arr)))

    opts = np.get_printoptions()
    np.set_printoptions(edgeitems=500)
    s = str(np.array2string(arr,
                          formatter={
                              'float_kind': lambda x: visual(x, max_val),
                              'int_kind': lambda x: visual(x, max_val)},
                          max_line_width=5000
                          ))
    np.set_printoptions(**opts)

    return s 
開發者ID:nyu-mll,項目名稱:PRPN-Analysis,代碼行數:18,代碼來源:hinton.py

示例10: get_printoptions

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def get_printoptions():
    """
    Return the current print options.

    Returns
    -------
    print_opts : dict
        Dictionary of current print options with keys

          - precision : int
          - threshold : int
          - edgeitems : int
          - linewidth : int
          - suppress : bool
          - nanstr : str
          - infstr : str
          - formatter : dict of callables
          - sign : str

        For a full description of these options, see `set_printoptions`.

    See Also
    --------
    set_printoptions, set_string_function

    """
    return _format_options.copy() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:29,代碼來源:arrayprint.py

示例11: printoptions

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_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

示例12: setup

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def setup(self):
        self.oldopts = np.get_printoptions() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_arrayprint.py

示例13: test_ctx_mgr_exceptions

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_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

示例14: _PrintMeanVar

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def _PrintMeanVar(self):
    m, v = self._ComputeMeanVar()
    original = np.get_printoptions()
    np.set_printoptions(threshold=np.inf)
    tf.logging.info('== Mean/variance.')
    tf.logging.info('mean = %s', m)
    tf.logging.info('var = %s', v)
    np.set_printoptions(**original) 
開發者ID:tensorflow,項目名稱:lingvo,代碼行數:10,代碼來源:compute_stats.py

示例15: _PrintOptions

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import get_printoptions [as 別名]
def _PrintOptions(*args, **kwargs):
  original = np.get_printoptions()
  np.set_printoptions(*args, **kwargs)
  try:
    yield
  finally:
    np.set_printoptions(**original) 
開發者ID:tensorflow,項目名稱:lingvo,代碼行數:9,代碼來源:py_utils.py


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