打印很大的numpy.array

2020年7月6日 / 9次阅读 / Last Modified 2020年7月6日
NumPy

一般情况下numpy.array里面的数据非常多,要全部打印出来也有点不现实,因为numpy对于打印,是有一套自己的规则的:

  • the last axis is printed from left to right,
  • the second-to-last is printed from top to bottom,
  • the rest are also printed from top to bottom, with each slice separated from the next by an empty line.

最高维度含有真正的数据,从左到右打印;倒数第2个维度,就从上到下打印了;其它的维度也都是从上到下打印,中间间隔一些空白行将部分数据省略掉。

我们来打一个10000个数据的araay看一下:

>>> a = np.arange(10000).reshape(10,10,10,10)
>>> a
array([[[[   0,    1,    2, ...,    7,    8,    9],
         [  10,   11,   12, ...,   17,   18,   19],
         [  20,   21,   22, ...,   27,   28,   29],
         ...,
         [  70,   71,   72, ...,   77,   78,   79],
         [  80,   81,   82, ...,   87,   88,   89],
         [  90,   91,   92, ...,   97,   98,   99]],

        [[ 100,  101,  102, ...,  107,  108,  109],
         [ 110,  111,  112, ...,  117,  118,  119],
         [ 120,  121,  122, ...,  127,  128,  129],
         ...,
         [ 170,  171,  172, ...,  177,  178,  179],
         [ 180,  181,  182, ...,  187,  188,  189],
         [ 190,  191,  192, ...,  197,  198,  199]],

        [[ 200,  201,  202, ...,  207,  208,  209],
         [ 210,  211,  212, ...,  217,  218,  219],
         [ 220,  221,  222, ...,  227,  228,  229],
         ...,
         [ 270,  271,  272, ...,  277,  278,  279],
         [ 280,  281,  282, ...,  287,  288,  289],
         [ 290,  291,  292, ...,  297,  298,  299]],

        ...,

        [[ 700,  701,  702, ...,  707,  708,  709],
         [ 710,  711,  712, ...,  717,  718,  719],
         [ 720,  721,  722, ...,  727,  728,  729],
         ...,
         [ 770,  771,  772, ...,  777,  778,  779],
         [ 780,  781,  782, ...,  787,  788,  789],
         [ 790,  791,  792, ...,  797,  798,  799]],

        [[ 800,  801,  802, ...,  807,  808,  809],
         [ 810,  811,  812, ...,  817,  818,  819],
         [ 820,  821,  822, ...,  827,  828,  829],
         ...,
         [ 870,  871,  872, ...,  877,  878,  879],
         [ 880,  881,  882, ...,  887,  888,  889],
         [ 890,  891,  892, ...,  897,  898,  899]],

        [[ 900,  901,  902, ...,  907,  908,  909],
         [ 910,  911,  912, ...,  917,  918,  919],
         [ 920,  921,  922, ...,  927,  928,  929],
         ...,
         [ 970,  971,  972, ...,  977,  978,  979],
         [ 980,  981,  982, ...,  987,  988,  989],
         [ 990,  991,  992, ...,  997,  998,  999]]],


       [[[1000, 1001, 1002, ..., 1007, 1008, 1009],
         [1010, 1011, 1012, ..., 1017, 1018, 1019],
         [1020, 1021, 1022, ..., 1027, 1028, 1029],
         ...,
         [1070, 1071, 1072, ..., 1077, 1078, 1079],
         [1080, 1081, 1082, ..., 1087, 1088, 1089],
         [1090, 1091, 1092, ..., 1097, 1098, 1099]],

        [[1100, 1101, 1102, ..., 1107, 1108, 1109],
         [1110, 1111, 1112, ..., 1117, 1118, 1119],
         [1120, 1121, 1122, ..., 1127, 1128, 1129],
         ...,
         [1170, 1171, 1172, ..., 1177, 1178, 1179],
         [1180, 1181, 1182, ..., 1187, 1188, 1189],
         [1190, 1191, 1192, ..., 1197, 1198, 1199]],

        [[1200, 1201, 1202, ..., 1207, 1208, 1209],
         [1210, 1211, 1212, ..., 1217, 1218, 1219],
         [1220, 1221, 1222, ..., 1227, 1228, 1229],
         ...,
         [1270, 1271, 1272, ..., 1277, 1278, 1279],
         [1280, 1281, 1282, ..., 1287, 1288, 1289],
         [1290, 1291, 1292, ..., 1297, 1298, 1299]],

        ...,

        [[1700, 1701, 1702, ..., 1707, 1708, 1709],
         [1710, 1711, 1712, ..., 1717, 1718, 1719],
         [1720, 1721, 1722, ..., 1727, 1728, 1729],
         ...,
         [1770, 1771, 1772, ..., 1777, 1778, 1779],
         [1780, 1781, 1782, ..., 1787, 1788, 1789],
         [1790, 1791, 1792, ..., 1797, 1798, 1799]],

        [[1800, 1801, 1802, ..., 1807, 1808, 1809],
         [1810, 1811, 1812, ..., 1817, 1818, 1819],
         [1820, 1821, 1822, ..., 1827, 1828, 1829],
         ...,
         [1870, 1871, 1872, ..., 1877, 1878, 1879],
         [1880, 1881, 1882, ..., 1887, 1888, 1889],
         [1890, 1891, 1892, ..., 1897, 1898, 1899]],

        [[1900, 1901, 1902, ..., 1907, 1908, 1909],
         [1910, 1911, 1912, ..., 1917, 1918, 1919],
         [1920, 1921, 1922, ..., 1927, 1928, 1929],
         ...,
         [1970, 1971, 1972, ..., 1977, 1978, 1979],
         [1980, 1981, 1982, ..., 1987, 1988, 1989],
         [1990, 1991, 1992, ..., 1997, 1998, 1999]]],


       [[[2000, 2001, 2002, ..., 2007, 2008, 2009],
         [2010, 2011, 2012, ..., 2017, 2018, 2019],
         [2020, 2021, 2022, ..., 2027, 2028, 2029],
         ...,
         [2070, 2071, 2072, ..., 2077, 2078, 2079],
         [2080, 2081, 2082, ..., 2087, 2088, 2089],
         [2090, 2091, 2092, ..., 2097, 2098, 2099]],

        [[2100, 2101, 2102, ..., 2107, 2108, 2109],
         [2110, 2111, 2112, ..., 2117, 2118, 2119],
         [2120, 2121, 2122, ..., 2127, 2128, 2129],
         ...,
         [2170, 2171, 2172, ..., 2177, 2178, 2179],
         [2180, 2181, 2182, ..., 2187, 2188, 2189],
         [2190, 2191, 2192, ..., 2197, 2198, 2199]],

        [[2200, 2201, 2202, ..., 2207, 2208, 2209],
         [2210, 2211, 2212, ..., 2217, 2218, 2219],
         [2220, 2221, 2222, ..., 2227, 2228, 2229],
         ...,
         [2270, 2271, 2272, ..., 2277, 2278, 2279],
         [2280, 2281, 2282, ..., 2287, 2288, 2289],
         [2290, 2291, 2292, ..., 2297, 2298, 2299]],

        ...,

        [[2700, 2701, 2702, ..., 2707, 2708, 2709],
         [2710, 2711, 2712, ..., 2717, 2718, 2719],
         [2720, 2721, 2722, ..., 2727, 2728, 2729],
         ...,
         [2770, 2771, 2772, ..., 2777, 2778, 2779],
         [2780, 2781, 2782, ..., 2787, 2788, 2789],
         [2790, 2791, 2792, ..., 2797, 2798, 2799]],

        [[2800, 2801, 2802, ..., 2807, 2808, 2809],
         [2810, 2811, 2812, ..., 2817, 2818, 2819],
         [2820, 2821, 2822, ..., 2827, 2828, 2829],
         ...,
         [2870, 2871, 2872, ..., 2877, 2878, 2879],
         [2880, 2881, 2882, ..., 2887, 2888, 2889],
         [2890, 2891, 2892, ..., 2897, 2898, 2899]],

        [[2900, 2901, 2902, ..., 2907, 2908, 2909],
         [2910, 2911, 2912, ..., 2917, 2918, 2919],
         [2920, 2921, 2922, ..., 2927, 2928, 2929],
         ...,
         [2970, 2971, 2972, ..., 2977, 2978, 2979],
         [2980, 2981, 2982, ..., 2987, 2988, 2989],
         [2990, 2991, 2992, ..., 2997, 2998, 2999]]],


       ...,


       [[[7000, 7001, 7002, ..., 7007, 7008, 7009],
         [7010, 7011, 7012, ..., 7017, 7018, 7019],
         [7020, 7021, 7022, ..., 7027, 7028, 7029],
         ...,
         [7070, 7071, 7072, ..., 7077, 7078, 7079],
         [7080, 7081, 7082, ..., 7087, 7088, 7089],
         [7090, 7091, 7092, ..., 7097, 7098, 7099]],

        [[7100, 7101, 7102, ..., 7107, 7108, 7109],
         [7110, 7111, 7112, ..., 7117, 7118, 7119],
         [7120, 7121, 7122, ..., 7127, 7128, 7129],
         ...,
         [7170, 7171, 7172, ..., 7177, 7178, 7179],
         [7180, 7181, 7182, ..., 7187, 7188, 7189],
         [7190, 7191, 7192, ..., 7197, 7198, 7199]],

        [[7200, 7201, 7202, ..., 7207, 7208, 7209],
         [7210, 7211, 7212, ..., 7217, 7218, 7219],
         [7220, 7221, 7222, ..., 7227, 7228, 7229],
         ...,
         [7270, 7271, 7272, ..., 7277, 7278, 7279],
         [7280, 7281, 7282, ..., 7287, 7288, 7289],
         [7290, 7291, 7292, ..., 7297, 7298, 7299]],

        ...,

        [[7700, 7701, 7702, ..., 7707, 7708, 7709],
         [7710, 7711, 7712, ..., 7717, 7718, 7719],
         [7720, 7721, 7722, ..., 7727, 7728, 7729],
         ...,
         [7770, 7771, 7772, ..., 7777, 7778, 7779],
         [7780, 7781, 7782, ..., 7787, 7788, 7789],
         [7790, 7791, 7792, ..., 7797, 7798, 7799]],

        [[7800, 7801, 7802, ..., 7807, 7808, 7809],
         [7810, 7811, 7812, ..., 7817, 7818, 7819],
         [7820, 7821, 7822, ..., 7827, 7828, 7829],
         ...,
         [7870, 7871, 7872, ..., 7877, 7878, 7879],
         [7880, 7881, 7882, ..., 7887, 7888, 7889],
         [7890, 7891, 7892, ..., 7897, 7898, 7899]],

        [[7900, 7901, 7902, ..., 7907, 7908, 7909],
         [7910, 7911, 7912, ..., 7917, 7918, 7919],
         [7920, 7921, 7922, ..., 7927, 7928, 7929],
         ...,
         [7970, 7971, 7972, ..., 7977, 7978, 7979],
         [7980, 7981, 7982, ..., 7987, 7988, 7989],
         [7990, 7991, 7992, ..., 7997, 7998, 7999]]],


       [[[8000, 8001, 8002, ..., 8007, 8008, 8009],
         [8010, 8011, 8012, ..., 8017, 8018, 8019],
         [8020, 8021, 8022, ..., 8027, 8028, 8029],
         ...,
         [8070, 8071, 8072, ..., 8077, 8078, 8079],
         [8080, 8081, 8082, ..., 8087, 8088, 8089],
         [8090, 8091, 8092, ..., 8097, 8098, 8099]],

        [[8100, 8101, 8102, ..., 8107, 8108, 8109],
         [8110, 8111, 8112, ..., 8117, 8118, 8119],
         [8120, 8121, 8122, ..., 8127, 8128, 8129],
         ...,
         [8170, 8171, 8172, ..., 8177, 8178, 8179],
         [8180, 8181, 8182, ..., 8187, 8188, 8189],
         [8190, 8191, 8192, ..., 8197, 8198, 8199]],

        [[8200, 8201, 8202, ..., 8207, 8208, 8209],
         [8210, 8211, 8212, ..., 8217, 8218, 8219],
         [8220, 8221, 8222, ..., 8227, 8228, 8229],
         ...,
         [8270, 8271, 8272, ..., 8277, 8278, 8279],
         [8280, 8281, 8282, ..., 8287, 8288, 8289],
         [8290, 8291, 8292, ..., 8297, 8298, 8299]],

        ...,

        [[8700, 8701, 8702, ..., 8707, 8708, 8709],
         [8710, 8711, 8712, ..., 8717, 8718, 8719],
         [8720, 8721, 8722, ..., 8727, 8728, 8729],
         ...,
         [8770, 8771, 8772, ..., 8777, 8778, 8779],
         [8780, 8781, 8782, ..., 8787, 8788, 8789],
         [8790, 8791, 8792, ..., 8797, 8798, 8799]],

        [[8800, 8801, 8802, ..., 8807, 8808, 8809],
         [8810, 8811, 8812, ..., 8817, 8818, 8819],
         [8820, 8821, 8822, ..., 8827, 8828, 8829],
         ...,
         [8870, 8871, 8872, ..., 8877, 8878, 8879],
         [8880, 8881, 8882, ..., 8887, 8888, 8889],
         [8890, 8891, 8892, ..., 8897, 8898, 8899]],

        [[8900, 8901, 8902, ..., 8907, 8908, 8909],
         [8910, 8911, 8912, ..., 8917, 8918, 8919],
         [8920, 8921, 8922, ..., 8927, 8928, 8929],
         ...,
         [8970, 8971, 8972, ..., 8977, 8978, 8979],
         [8980, 8981, 8982, ..., 8987, 8988, 8989],
         [8990, 8991, 8992, ..., 8997, 8998, 8999]]],


       [[[9000, 9001, 9002, ..., 9007, 9008, 9009],
         [9010, 9011, 9012, ..., 9017, 9018, 9019],
         [9020, 9021, 9022, ..., 9027, 9028, 9029],
         ...,
         [9070, 9071, 9072, ..., 9077, 9078, 9079],
         [9080, 9081, 9082, ..., 9087, 9088, 9089],
         [9090, 9091, 9092, ..., 9097, 9098, 9099]],

        [[9100, 9101, 9102, ..., 9107, 9108, 9109],
         [9110, 9111, 9112, ..., 9117, 9118, 9119],
         [9120, 9121, 9122, ..., 9127, 9128, 9129],
         ...,
         [9170, 9171, 9172, ..., 9177, 9178, 9179],
         [9180, 9181, 9182, ..., 9187, 9188, 9189],
         [9190, 9191, 9192, ..., 9197, 9198, 9199]],

        [[9200, 9201, 9202, ..., 9207, 9208, 9209],
         [9210, 9211, 9212, ..., 9217, 9218, 9219],
         [9220, 9221, 9222, ..., 9227, 9228, 9229],
         ...,
         [9270, 9271, 9272, ..., 9277, 9278, 9279],
         [9280, 9281, 9282, ..., 9287, 9288, 9289],
         [9290, 9291, 9292, ..., 9297, 9298, 9299]],

        ...,

        [[9700, 9701, 9702, ..., 9707, 9708, 9709],
         [9710, 9711, 9712, ..., 9717, 9718, 9719],
         [9720, 9721, 9722, ..., 9727, 9728, 9729],
         ...,
         [9770, 9771, 9772, ..., 9777, 9778, 9779],
         [9780, 9781, 9782, ..., 9787, 9788, 9789],
         [9790, 9791, 9792, ..., 9797, 9798, 9799]],

        [[9800, 9801, 9802, ..., 9807, 9808, 9809],
         [9810, 9811, 9812, ..., 9817, 9818, 9819],
         [9820, 9821, 9822, ..., 9827, 9828, 9829],
         ...,
         [9870, 9871, 9872, ..., 9877, 9878, 9879],
         [9880, 9881, 9882, ..., 9887, 9888, 9889],
         [9890, 9891, 9892, ..., 9897, 9898, 9899]],

        [[9900, 9901, 9902, ..., 9907, 9908, 9909],
         [9910, 9911, 9912, ..., 9917, 9918, 9919],
         [9920, 9921, 9922, ..., 9927, 9928, 9929],
         ...,
         [9970, 9971, 9972, ..., 9977, 9978, 9979],
         [9980, 9981, 9982, ..., 9987, 9988, 9989],
         [9990, 9991, 9992, ..., 9997, 9998, 9999]]]])

其实,最后一个axis如果数据很多,中间也有省略。你会发现numpy打印出来的都是数据的4个角!

如果想全部打印出来看,有办法吗?有啊,自己写for-loop。另外就是使用 np.set_printoptions:

>>> np.set_printoptions(threshold=sys.maxsize)

我就不打印a了,太长了。。。请自己测试一下吧。

-- EOF --

本文链接:https://www.pynote.net/archives/2163

留言区

电子邮件地址不会被公开。 必填项已用*标注


前一篇:
后一篇:

More


©Copyright 麦新杰 Since 2019 Python笔记

go to top