知っていて当たり前-03　配列の出力

# 配列の出力


```julia
a = rand(3, 3)
```




    3×3 Matrix{Float64}:
     0.971     0.326636  0.396373
     0.473502  0.434699  0.636328
     0.990813  0.756185  0.573263



print() での出力は場合によっては不適切

## 1.　`print()`


```julia
print(round.(a, digits=2))
```

    [0.97 0.33 0.4; 0.47 0.43 0.64; 0.99 0.76 0.57]

## 2.　`display()`


```julia
display(a)
```


    3×3 Matrix{Float64}:
     0.971     0.326636  0.396373
     0.473502  0.434699  0.636328
     0.990813  0.756185  0.573263


## 3.　`@show`


```julia
@show a
```

    a = [0.9710004177422338 0.3266361050649256 0.39637341788176683; 0.473502253224818 0.43469895102016876 0.6363277807621343; 0.9908126761551026 0.7561845212865852 0.5732633845198112]





    3×3 Matrix{Float64}:
     0.971     0.326636  0.396373
     0.473502  0.434699  0.636328
     0.990813  0.756185  0.573263



## 4.　`print_matrix()`


```julia
Base.print_matrix(stdout, a)
```

     0.9710004177422338  0.3266361050649256   0.39637341788176683
     0.473502253224818   0.43469895102016876  0.6363277807621343
     0.9908126761551026  0.7561845212865852   0.5732633845198112

### 4.1.　空白区切り


```julia
Base.print_matrix(stdout, round.(a, digits=2), "", " ", "\n")
```

    0.97 0.33 0.4
    0.47 0.43 0.64
    0.99 0.76 0.57


### 4.2.　タブ区切り


```julia
Base.print_matrix(stdout, round.(a, digits=2), "", "\t", "\n")
```

    0.97	0.33	0.4
    0.47	0.43	0.64
    0.99	0.76	0.57


### 4.3.　カンマ区切り


```julia
Base.print_matrix(stdout, round.(a, digits=2), "", ",", "\n")
```

    0.97,0.33,0.4
    0.47,0.43,0.64
    0.99,0.76,0.57


### 4.4.　区切り文字の他に，前と後にも文字列を付けることができる


```julia
Base.print_matrix(stdout, round.(a, digits=2), "[ ", "; ", "]\n")
```

    [ 0.97; 0.33; 0.4
      0.47; 0.43; 0.64
      0.99; 0.76; 0.57]


## 5.　ファイルに書き出す


```julia
open("out.txt","w") do file
    Base.print_array(file, a)
end
```

## 6.　巨大配列も全てプリントする

普通では，途中が省略される。


```julia
x = randn(50, 3);
io = IOContext(stdout, :limit => false)
x
```




    50×3 Matrix{Float64}:
      0.611644   0.563448    1.58911
     -1.16499   -0.810368    0.13231
      0.240979  -0.446526    0.768439
      0.351147  -0.949517   -0.269682
      0.601815  -1.20914     0.0658539
      0.906893   0.13659    -0.137288
     -1.3325    -1.16614    -0.0873196
      0.476415  -0.861375    1.822
      0.1247     0.718505   -1.86516
      0.539112   1.45856    -0.119367
      1.38781    0.793228    2.56556
      1.35815    0.947712    0.067429
      0.378962  -0.0289364  -0.428118
      ⋮                     
      0.757231  -1.67966     1.08943
     -0.224571  -0.304788   -1.44341
      0.437547  -0.303445   -0.168812
      1.6152    -0.522008    1.44208
      1.61944    1.1039      0.0598789
     -0.775724   0.460265    0.561002
      0.442743  -0.948905    2.33314
      0.170534  -1.61885     0.640008
      1.4124     0.52855     0.57386
      0.734671   1.03267    -0.140571
     -0.875223   1.309       0.18523
      0.552932   1.58439     1.39876



以下のようにすれば，全部表示される。


```julia
Base.print_matrix(io, x)
```

      0.6116436270034457    0.5634476195920002    1.589112560076304
     -1.1649933382716848   -0.810368202289555     0.13230982822567622
      0.24097894140899087  -0.4465263888744867    0.7684385981033044
      0.35114713765645256  -0.9495173634700325   -0.2696815085845762
      0.6018152147278529   -1.2091380461685117    0.06585392837625016
      0.9068928522704546    0.13658999203896122  -0.13728786232710838
     -1.3324959828343956   -1.1661446661286523   -0.08731961729756431
      0.4764152501496235   -0.8613750794479739    1.8219971493175455
      0.1246999300011082    0.7185054414707505   -1.8651592263730552
      0.5391115386756626    1.4585629316351396   -0.11936692551847612
      1.3878116198491182    0.7932280055267469    2.5655593920657758
      1.3581497455965281    0.9477120476079164    0.06742902363056077
      0.37896238731254117  -0.02893637000312291  -0.42811770981919894
      1.0632229605334886    0.05799570729790041  -0.051897406979173916
     -1.5381689878295837   -0.29069685292719755   0.1478782410559024
     -0.6321512417422394   -0.24850566201599483  -0.421104667485486
     -0.2217078257885308    0.4978768021285621    0.1116739507441453
     -0.6660441711837705   -1.1634858057534379    0.21662353083441388
     -0.7030646516518918    0.9382101055291597   -0.18889624906097893
     -0.4183646080623141   -0.6542312781848486   -1.1714533730743935
     -1.4672843487665064    0.9891582728162546   -0.012464493861671101
     -1.3460603922589178   -1.586550485456791    -0.10991824141073504
      0.3895328084008815    0.01835164631530351   0.7101083960310287
     -0.742873113926507     0.6489563145454944    1.1593286784802241
      0.48490256381543484   0.5624340609610982   -0.2598148506665157
      0.26924647270707763  -1.2922858630132263    1.070598780807298
     -0.07368499656529995   0.2330049994656906    0.9117133347395303
     -0.7378158816890067    1.125063821558758     1.3925721944059495
     -1.0402979694038827   -0.32482065472961785  -1.7854994181950261
      0.6379804089883835    1.0403596445740382   -0.6865691255390357
      0.5824125401875188    1.3337360131070504    0.812677840511916
     -0.06817519710485957   0.3775987021769519    2.50209825501281
     -0.7198512167126965    0.283319844613077     1.1709791790705315
     -2.2667801010467836    0.44174942711109344   0.4430607358478767
     -0.8999115673730017   -2.5900485460143927    1.3467440274395441
      0.27977983186551136  -0.16558300100166054   0.6698510649045393
     -0.12420244333953867   1.5555915787520829   -0.7774547149529986
      1.4763022257319798    0.8043440514117746    0.3345564652404459
      0.7572313880879572   -1.6796557875432157    1.0894279744315367
     -0.22457083872434294  -0.3047881080946263   -1.443409128925922
      0.4375467488868471   -0.3034449236746218   -0.16881222391679115
      1.6151987643165713   -0.5220078505741127    1.4420783868363318
      1.6194430682264334    1.1038952825052242    0.05987892924011612
     -0.7757238502527151    0.46026512689443555   0.5610020395907171
      0.44274323861830883  -0.9489045648025605    2.3331381160426443
      0.1705339515989674   -1.6188496464141517    0.6400076745596067
      1.41239629342457      0.5285496029079239    0.5738604125441862
      0.7346707346007644    1.0326671433773142   -0.14057129365840915
     -0.8752232472730248    1.3089951426223145    0.18523000627129085
      0.5529319952835351    1.5843863713716497    1.3987582810486519


```julia
Base.print_matrix(io, round.(x, digits=2), "", "\t", "\n")
```

     0.61	 0.56	 1.59
    -1.16	-0.81	 0.13
     0.24	-0.45	 0.77
     0.35	-0.95	-0.27
     0.6 	-1.21	 0.07
     0.91	 0.14	-0.14
    -1.33	-1.17	-0.09
     0.48	-0.86	 1.82
     0.12	 0.72	-1.87
     0.54	 1.46	-0.12
     1.39	 0.79	 2.57
     1.36	 0.95	 0.07
     0.38	-0.03	-0.43
     1.06	 0.06	-0.05
    -1.54	-0.29	 0.15
    -0.63	-0.25	-0.42
    -0.22	 0.5 	 0.11
    -0.67	-1.16	 0.22
    -0.7 	 0.94	-0.19
    -0.42	-0.65	-1.17
    -1.47	 0.99	-0.01
    -1.35	-1.59	-0.11
     0.39	 0.02	 0.71
    -0.74	 0.65	 1.16
     0.48	 0.56	-0.26
     0.27	-1.29	 1.07
    -0.07	 0.23	 0.91
    -0.74	 1.13	 1.39
    -1.04	-0.32	-1.79
     0.64	 1.04	-0.69
     0.58	 1.33	 0.81
    -0.07	 0.38	 2.5
    -0.72	 0.28	 1.17
    -2.27	 0.44	 0.44
    -0.9 	-2.59	 1.35
     0.28	-0.17	 0.67
    -0.12	 1.56	-0.78
     1.48	 0.8 	 0.33
     0.76	-1.68	 1.09
    -0.22	-0.3 	-1.44
     0.44	-0.3 	-0.17
     1.62	-0.52	 1.44
     1.62	 1.1 	 0.06
    -0.78	 0.46	 0.56
     0.44	-0.95	 2.33
     0.17	-1.62	 0.64
     1.41	 0.53	 0.57
     0.73	 1.03	-0.14
    -0.88	 1.31	 0.19
     0.55	 1.58	 1.4



```julia
Base.print_array(io, x)
```

      0.6116436270034457    0.5634476195920002    1.589112560076304
     -1.1649933382716848   -0.810368202289555     0.13230982822567622
      0.24097894140899087  -0.4465263888744867    0.7684385981033044
      0.35114713765645256  -0.9495173634700325   -0.2696815085845762
      0.6018152147278529   -1.2091380461685117    0.06585392837625016
      0.9068928522704546    0.13658999203896122  -0.13728786232710838
     -1.3324959828343956   -1.1661446661286523   -0.08731961729756431
      0.4764152501496235   -0.8613750794479739    1.8219971493175455
      0.1246999300011082    0.7185054414707505   -1.8651592263730552
      0.5391115386756626    1.4585629316351396   -0.11936692551847612
      1.3878116198491182    0.7932280055267469    2.5655593920657758
      1.3581497455965281    0.9477120476079164    0.06742902363056077
      0.37896238731254117  -0.02893637000312291  -0.42811770981919894
      1.0632229605334886    0.05799570729790041  -0.051897406979173916
     -1.5381689878295837   -0.29069685292719755   0.1478782410559024
     -0.6321512417422394   -0.24850566201599483  -0.421104667485486
     -0.2217078257885308    0.4978768021285621    0.1116739507441453
     -0.6660441711837705   -1.1634858057534379    0.21662353083441388
     -0.7030646516518918    0.9382101055291597   -0.18889624906097893
     -0.4183646080623141   -0.6542312781848486   -1.1714533730743935
     -1.4672843487665064    0.9891582728162546   -0.012464493861671101
     -1.3460603922589178   -1.586550485456791    -0.10991824141073504
      0.3895328084008815    0.01835164631530351   0.7101083960310287
     -0.742873113926507     0.6489563145454944    1.1593286784802241
      0.48490256381543484   0.5624340609610982   -0.2598148506665157
      0.26924647270707763  -1.2922858630132263    1.070598780807298
     -0.07368499656529995   0.2330049994656906    0.9117133347395303
     -0.7378158816890067    1.125063821558758     1.3925721944059495
     -1.0402979694038827   -0.32482065472961785  -1.7854994181950261
      0.6379804089883835    1.0403596445740382   -0.6865691255390357
      0.5824125401875188    1.3337360131070504    0.812677840511916
     -0.06817519710485957   0.3775987021769519    2.50209825501281
     -0.7198512167126965    0.283319844613077     1.1709791790705315
     -2.2667801010467836    0.44174942711109344   0.4430607358478767
     -0.8999115673730017   -2.5900485460143927    1.3467440274395441
      0.27977983186551136  -0.16558300100166054   0.6698510649045393
     -0.12420244333953867   1.5555915787520829   -0.7774547149529986
      1.4763022257319798    0.8043440514117746    0.3345564652404459
      0.7572313880879572   -1.6796557875432157    1.0894279744315367
     -0.22457083872434294  -0.3047881080946263   -1.443409128925922
      0.4375467488868471   -0.3034449236746218   -0.16881222391679115
      1.6151987643165713   -0.5220078505741127    1.4420783868363318
      1.6194430682264334    1.1038952825052242    0.05987892924011612
     -0.7757238502527151    0.46026512689443555   0.5610020395907171
      0.44274323861830883  -0.9489045648025605    2.3331381160426443
      0.1705339515989674   -1.6188496464141517    0.6400076745596067
      1.41239629342457      0.5285496029079239    0.5738604125441862
      0.7346707346007644    1.0326671433773142   -0.14057129365840915
     -0.8752232472730248    1.3089951426223145    0.18523000627129085
      0.5529319952835351    1.5843863713716497    1.3987582810486519

以下の場合にはやはり途中が省略される。


```julia
io = IOContext(stdout, :limit => true)
Base.print_matrix(io, x)
```

      0.6116436270034457    0.5634476195920002    1.589112560076304
     -1.1649933382716848   -0.810368202289555     0.13230982822567622
      0.24097894140899087  -0.4465263888744867    0.7684385981033044
      0.35114713765645256  -0.9495173634700325   -0.2696815085845762
      0.6018152147278529   -1.2091380461685117    0.06585392837625016
      0.9068928522704546    0.13658999203896122  -0.13728786232710838
     -1.3324959828343956   -1.1661446661286523   -0.08731961729756431
      0.4764152501496235   -0.8613750794479739    1.8219971493175455
      0.1246999300011082    0.7185054414707505   -1.8651592263730552
      0.5391115386756626    1.4585629316351396   -0.11936692551847612
      1.3878116198491182    0.7932280055267469    2.5655593920657758
      1.3581497455965281    0.9477120476079164    0.06742902363056077
      0.37896238731254117  -0.02893637000312291  -0.42811770981919894
      ⋮                                          
      0.7572313880879572   -1.6796557875432157    1.0894279744315367
     -0.22457083872434294  -0.3047881080946263   -1.443409128925922
      0.4375467488868471   -0.3034449236746218   -0.16881222391679115
      1.6151987643165713   -0.5220078505741127    1.4420783868363318
      1.6194430682264334    1.1038952825052242    0.05987892924011612
     -0.7757238502527151    0.46026512689443555   0.5610020395907171
      0.44274323861830883  -0.9489045648025605    2.3331381160426443
      0.1705339515989674   -1.6188496464141517    0.6400076745596067
      1.41239629342457      0.5285496029079239    0.5738604125441862
      0.7346707346007644    1.0326671433773142   -0.14057129365840915
     -0.8752232472730248    1.3089951426223145    0.18523000627129085
      0.5529319952835351    1.5843863713716497    1.3987582810486519

以下のようにすれば，全部表示できる。


```julia
function myshowall(io, x, limit = false)
  println(io, summary(x), ":")
  Base.print_matrix(IOContext(io, :limit => limit), x)
end

summary(x)
```




    "50×3 Matrix{Float64}"




```julia
println(stdout, summary(x))
```

    50×3 Matrix{Float64}



```julia
Base.print_matrix(IOContext(stdout, :limit => false), x)
```

      0.6116436270034457    0.5634476195920002    1.589112560076304
     -1.1649933382716848   -0.810368202289555     0.13230982822567622
      0.24097894140899087  -0.4465263888744867    0.7684385981033044
      0.35114713765645256  -0.9495173634700325   -0.2696815085845762
      0.6018152147278529   -1.2091380461685117    0.06585392837625016
      0.9068928522704546    0.13658999203896122  -0.13728786232710838
     -1.3324959828343956   -1.1661446661286523   -0.08731961729756431
      0.4764152501496235   -0.8613750794479739    1.8219971493175455
      0.1246999300011082    0.7185054414707505   -1.8651592263730552
      0.5391115386756626    1.4585629316351396   -0.11936692551847612
      1.3878116198491182    0.7932280055267469    2.5655593920657758
      1.3581497455965281    0.9477120476079164    0.06742902363056077
      0.37896238731254117  -0.02893637000312291  -0.42811770981919894
      1.0632229605334886    0.05799570729790041  -0.051897406979173916
     -1.5381689878295837   -0.29069685292719755   0.1478782410559024
     -0.6321512417422394   -0.24850566201599483  -0.421104667485486
     -0.2217078257885308    0.4978768021285621    0.1116739507441453
     -0.6660441711837705   -1.1634858057534379    0.21662353083441388
     -0.7030646516518918    0.9382101055291597   -0.18889624906097893
     -0.4183646080623141   -0.6542312781848486   -1.1714533730743935
     -1.4672843487665064    0.9891582728162546   -0.012464493861671101
     -1.3460603922589178   -1.586550485456791    -0.10991824141073504
      0.3895328084008815    0.01835164631530351   0.7101083960310287
     -0.742873113926507     0.6489563145454944    1.1593286784802241
      0.48490256381543484   0.5624340609610982   -0.2598148506665157
      0.26924647270707763  -1.2922858630132263    1.070598780807298
     -0.07368499656529995   0.2330049994656906    0.9117133347395303
     -0.7378158816890067    1.125063821558758     1.3925721944059495
     -1.0402979694038827   -0.32482065472961785  -1.7854994181950261
      0.6379804089883835    1.0403596445740382   -0.6865691255390357
      0.5824125401875188    1.3337360131070504    0.812677840511916
     -0.06817519710485957   0.3775987021769519    2.50209825501281
     -0.7198512167126965    0.283319844613077     1.1709791790705315
     -2.2667801010467836    0.44174942711109344   0.4430607358478767
     -0.8999115673730017   -2.5900485460143927    1.3467440274395441
      0.27977983186551136  -0.16558300100166054   0.6698510649045393
     -0.12420244333953867   1.5555915787520829   -0.7774547149529986
      1.4763022257319798    0.8043440514117746    0.3345564652404459
      0.7572313880879572   -1.6796557875432157    1.0894279744315367
     -0.22457083872434294  -0.3047881080946263   -1.443409128925922
      0.4375467488868471   -0.3034449236746218   -0.16881222391679115
      1.6151987643165713   -0.5220078505741127    1.4420783868363318
      1.6194430682264334    1.1038952825052242    0.05987892924011612
     -0.7757238502527151    0.46026512689443555   0.5610020395907171
      0.44274323861830883  -0.9489045648025605    2.3331381160426443
      0.1705339515989674   -1.6188496464141517    0.6400076745596067
      1.41239629342457      0.5285496029079239    0.5738604125441862
      0.7346707346007644    1.0326671433773142   -0.14057129365840915
     -0.8752232472730248    1.3089951426223145    0.18523000627129085
      0.5529319952835351    1.5843863713716497    1.3987582810486519


```julia
myshowall(stdout, x)
```

    50×3 Matrix{Float64}:
      0.6116436270034457    0.5634476195920002    1.589112560076304
     -1.1649933382716848   -0.810368202289555     0.13230982822567622
      0.24097894140899087  -0.4465263888744867    0.7684385981033044
      0.35114713765645256  -0.9495173634700325   -0.2696815085845762
      0.6018152147278529   -1.2091380461685117    0.06585392837625016
      0.9068928522704546    0.13658999203896122  -0.13728786232710838
     -1.3324959828343956   -1.1661446661286523   -0.08731961729756431
      0.4764152501496235   -0.8613750794479739    1.8219971493175455
      0.1246999300011082    0.7185054414707505   -1.8651592263730552
      0.5391115386756626    1.4585629316351396   -0.11936692551847612
      1.3878116198491182    0.7932280055267469    2.5655593920657758
      1.3581497455965281    0.9477120476079164    0.06742902363056077
      0.37896238731254117  -0.02893637000312291  -0.42811770981919894
      1.0632229605334886    0.05799570729790041  -0.051897406979173916
     -1.5381689878295837   -0.29069685292719755   0.1478782410559024
     -0.6321512417422394   -0.24850566201599483  -0.421104667485486
     -0.2217078257885308    0.4978768021285621    0.1116739507441453
     -0.6660441711837705   -1.1634858057534379    0.21662353083441388
     -0.7030646516518918    0.9382101055291597   -0.18889624906097893
     -0.4183646080623141   -0.6542312781848486   -1.1714533730743935
     -1.4672843487665064    0.9891582728162546   -0.012464493861671101
     -1.3460603922589178   -1.586550485456791    -0.10991824141073504
      0.3895328084008815    0.01835164631530351   0.7101083960310287
     -0.742873113926507     0.6489563145454944    1.1593286784802241
      0.48490256381543484   0.5624340609610982   -0.2598148506665157
      0.26924647270707763  -1.2922858630132263    1.070598780807298
     -0.07368499656529995   0.2330049994656906    0.9117133347395303
     -0.7378158816890067    1.125063821558758     1.3925721944059495
     -1.0402979694038827   -0.32482065472961785  -1.7854994181950261
      0.6379804089883835    1.0403596445740382   -0.6865691255390357
      0.5824125401875188    1.3337360131070504    0.812677840511916
     -0.06817519710485957   0.3775987021769519    2.50209825501281
     -0.7198512167126965    0.283319844613077     1.1709791790705315
     -2.2667801010467836    0.44174942711109344   0.4430607358478767
     -0.8999115673730017   -2.5900485460143927    1.3467440274395441
      0.27977983186551136  -0.16558300100166054   0.6698510649045393
     -0.12420244333953867   1.5555915787520829   -0.7774547149529986
      1.4763022257319798    0.8043440514117746    0.3345564652404459
      0.7572313880879572   -1.6796557875432157    1.0894279744315367
     -0.22457083872434294  -0.3047881080946263   -1.443409128925922
      0.4375467488868471   -0.3034449236746218   -0.16881222391679115
      1.6151987643165713   -0.5220078505741127    1.4420783868363318
      1.6194430682264334    1.1038952825052242    0.05987892924011612
     -0.7757238502527151    0.46026512689443555   0.5610020395907171
      0.44274323861830883  -0.9489045648025605    2.3331381160426443
      0.1705339515989674   -1.6188496464141517    0.6400076745596067
      1.41239629342457      0.5285496029079239    0.5738604125441862
      0.7346707346007644    1.0326671433773142   -0.14057129365840915
     -0.8752232472730248    1.3089951426223145    0.18523000627129085
      0.5529319952835351    1.5843863713716497    1.3987582810486519