質問

私が印ても済む配列を取得しま切り捨て表現かもしれないけど、私の配列になります。

はありません。

例:

>>> numpy.arange(10000)
array([   0,    1,    2, ..., 9997, 9998, 9999])

>>> numpy.arange(10000).reshape(250,40)
array([[   0,    1,    2, ...,   37,   38,   39],
       [  40,   41,   42, ...,   77,   78,   79],
       [  80,   81,   82, ...,  117,  118,  119],
       ..., 
       [9880, 9881, 9882, ..., 9917, 9918, 9919],
       [9920, 9921, 9922, ..., 9957, 9958, 9959],
       [9960, 9961, 9962, ..., 9997, 9998, 9999]])
役に立ちましたか?

解決

使用 numpy.set_printoptionsするます:

import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)

他のヒント

import numpy as np
np.set_printoptions(threshold=np.inf)

私は他の人によって提案されたnp.inf代わりのnp.nanを使用することをお勧め。あなたの目的のために彼らは仕事の両方が、「無限」にしきい値を設定することで、それはあなたが何を意味するか、あなたのコードを読んで皆に明らかです。 「非数」のしきい値を持つことは私には少し漠然としたようです。

前の答えは正しいものですが、弱い代替として、あなたはリストに変換することができます:

>>> numpy.arange(100).reshape(25,4).tolist()

[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19], [20, 21,
22, 23], [24, 25, 26, 27], [28, 29, 30, 31], [32, 33, 34, 35], [36, 37, 38, 39], [40, 41,
42, 43], [44, 45, 46, 47], [48, 49, 50, 51], [52, 53, 54, 55], [56, 57, 58, 59], [60, 61,
62, 63], [64, 65, 66, 67], [68, 69, 70, 71], [72, 73, 74, 75], [76, 77, 78, 79], [80, 81,
82, 83], [84, 85, 86, 87], [88, 89, 90, 91], [92, 93, 94, 95], [96, 97, 98, 99]]

あなたがnumpyのを使っているようなこの音ます。

そのような場合は、追加することができます:

import numpy as np
np.set_printoptions(threshold=np.nan)

これは、コーナーの印刷を無効にします。詳細については、この numpyのチュートリアルに。

を参照してください

はここで一回限りの方法でこれを行うには、あなたのデフォルト設定を変更したくない場合に便利です。

def fullprint(*args, **kwargs):
  from pprint import pprint
  import numpy
  opt = numpy.get_printoptions()
  numpy.set_printoptions(threshold='nan')
  pprint(*args, **kwargs)
  numpy.set_printoptions(**opt)

ポール・価格とコンテキストマネージャを使用する sugggested

import numpy as np


class fullprint:
    'context manager for printing full numpy arrays'

    def __init__(self, **kwargs):
        kwargs.setdefault('threshold', np.inf)
        self.opt = kwargs

    def __enter__(self):
        self._opt = np.get_printoptions()
        np.set_printoptions(**self.opt)

    def __exit__(self, type, value, traceback):
        np.set_printoptions(**self._opt)

a = np.arange(1001)

with fullprint():
    print(a)

print(a)

with fullprint(threshold=None, edgeitems=10):
    print(a)

numpyの1.15以降

あなたがnumpyの1.15(2018年7月23日リリース)以降を使用する場合は、printoptionsコンテキストマネージャを使用することができます:

with numpy.printoptions(threshold=numpy.inf):
    print(arr)

(それはあなたがnumpyをインポートする方法だ場合はもちろん、npによってnumpyを置き換える)

コンテキストマネージャ(with-ブロック)コンテキストマネージャが終了した後、印刷オプションは、ブロックが開始する前に彼らがいたどんな状態に戻りますことを保証を使用します。これは、設定が一時的なものであり、そして唯一のブロック内のコードに適用される保証します。

のための numpy.printoptionsドキュメントを参照してください。コンテキストマネージャについての詳細は、どのような他の引数それがサポートしています。

numpy.savetxt

numpy.savetxt(sys.stdout, numpy.arange(10000))

やが必要な場合は、文字列:

import StringIO
sio = StringIO.StringIO()
numpy.savetxt(sio, numpy.arange(10000))
s = sio.getvalue()
print s

デフォルトの出力形式:

0.000000000000000000e+00
1.000000000000000000e+00
2.000000000000000000e+00
3.000000000000000000e+00
...

で設定できる引数になります。

ントに特に注意してくださいこうでもないのは、角括弧を可能にする多くのカスタマイズしてお話ししたように、これまで: 印刷するにはどうしても済む配列なしにカッコ?

試Python2.7.12,ても済む1.11.1.

このは若干の修正である(set_printoptions)of neokするの答えに追加の引数を渡すためのオプションを削除します。

それはあなたが簡単に、このようなAを作成するために、 contextlib.contextmanager を使用する方法を示します少ないコード行でcontextmanagerます:

import numpy as np
from contextlib import contextmanager

@contextmanager
def show_complete_array():
    oldoptions = np.get_printoptions()
    np.set_printoptions(threshold=np.inf)
    try:
        yield
    finally:
        np.set_printoptions(**oldoptions)

あなたのコードでは、このように使用することができます:

a = np.arange(1001)

print(a)      # shows the truncated array

with show_complete_array():
    print(a)  # shows the complete array

print(a)      # shows the truncated array (again)

相補(numpy.set_printoptions(threshold=numpy.nan)で固定)の列数の最大値からこの回答するに、文字の限界もあります表示します。 (むしろインタラクティブセッションより)のbashからのpythonを呼び出す場合のようないくつかの環境では、これは以下のようにパラメータlinewidthを設定することによって固定することができる。

import numpy as np
np.set_printoptions(linewidth=2000)    # default = 75
Mat = np.arange(20000,20150).reshape(2,75)    # 150 elements (75 columns)
print(Mat)

この場合、あなたの窓は行をラップする文字の数を制限する必要があります。

が崇高なテキストを使用して、出力ウィンドウ内の結果を確認したいアウトのために、あなたは崇高-ビルドファイル[<のhref = "https://forum.sublimetext.com/tにビルド・オプション"word_wrap": falseを追加する必要があります/崇高テキスト-3-方法・ツー・ディスエーブル・ワードラップ・イン・ビルド出力/ 2" 分の9907のrel = "noreferrer">ソースの]。

これをオフにして通常モードに戻るには、

np.set_printoptions(threshold=False)

あなたがnumpyの配列

を持っていると仮定
 arr = numpy.arange(10000).reshape(250,40)

あなたは(np.set_printoptionsをトグルせずに)一回限りの方法で完全な配列を印刷したい場合は、しかし、コンテキストマネージャよりも簡単なもの(以下コード)をしたい、ちょうどDO

for row in arr:
     print row 

あなたはarray2string機能を使用することができます - <のhref = "https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.array2string.html#numpy.array2string" のrel =」 nofollowをnoreferrer ">ドキュメントがします。

a = numpy.arange(10000).reshape(250,40)
print(numpy.array2string(a, threshold=numpy.nan, max_line_width=numpy.nan))
# [Big output]
詳細は、

numpyのバージョン1.16以降では、 GitHubのチケット12251 のを参照してください。

from sys import maxsize
from numpy import set_printoptions

set_printoptions(threshold=maxsize)

あなたはいつも、特に大きな配列のために、すべての項目が印刷されたくはありません。

複数の項目を表示する簡単な方法:

In [349]: ar
Out[349]: array([1, 1, 1, ..., 0, 0, 0])

In [350]: ar[:100]
Out[350]:
array([1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1,
       1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1])

デフォルトでは、配列<1000スライスされたときには、罰金に動作します。

の場合配列が大きすぎる印刷しても済む自動的にスキップの中央部分配列のみを印刷するコーナーを無効にすること行動力とても済むプ全体の配列を変更することができます。印刷オプションを使用 set_printoptions.

>>> np.set_printoptions(threshold='nan')

または

>>> np.set_printoptions(edgeitems=3,infstr='inf',
... linewidth=75, nanstr='nan', precision=8,
... suppress=False, threshold=1000, formatter=None)

していますのでご覧ください、 ても済む文書 ても済む文書"の一部" 詳します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top