#author("2021-07-04T23:29:42+09:00","default:Miyashita","Miyashita")
#author("2024-03-08T11:57:22+09:00","default:Miyashita","Miyashita")
*内包表記 [#i3ac6fc6]
Python でいうリスト内包表記みたいなやつ.~
いつも忘れてはググっているのでメモ.~

**基本 [#e9898ee7]
普通.
#codeprettify(lang-julia){{
julia> [i*10 for i in 10:10:30]
3-element Array{Int64,1}:
 100
 200
 300
}}
~
~

**多重ループで多次元配列 [#j133788d]
ループ変数の間に for を入れずに "," で区切る.
#codeprettify(lang-julia){{
julia> [i+j for i in 10:10:30, j in 1:5]
3×5 Array{Int64,2}:
 11  12  13  14  15
 21  22  23  24  25
 31  32  33  34  35
}}
~
~

**多重ループで1次元配列 [#i25178b3]
for を繋げていくだけ.
#codeprettify(lang-julia){{
julia> [i+j for i in 10:10:30 for j in 1:5]
15-element Array{Int64,1}:
 11
 12
 13
 14
 15
 21
 22
 23
 24
 25
 31
 32
 33
 34
 35
}}
~
~

**多重ループで1次元配列,条件付き [#jb21bdc4]
#codeprettify(lang-julia){{
[i+j for i in 10:10:30, j in 1:5 if mod(i+j,3)==0]
5-element Array{Int64,1}:
 21
 12
 33
 24
 15
}}
~
~

***参考 [#bc0f2f2c]
#htmlinsert(amazon,transitional,"asins=433902905X,978-4339029055")
-[[超入門 - julia について>http://www.cas.cmc.osaka-u.ac.jp/~paoon/misc/julia/post/basic/]]

Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes