プログラミング/julia/juliaの文法
ここを見ると大体分かる†
変数のスコープを制限する†
特に jupyter などで不用意にグローバル変数を作らないようにするために、 try end ブロックを使うと良い気がする。
import Plots
Plots.gr()
try
data = rand(10)
Plots.plot(data)
end
# ここでは data は未定義
gist: https://gist.github.com/osamutake/fbbbd99c8f670335fa55afc0bfaa0438
ネストした内包表現†
大きな違いがある。
# 行 列
In : [(i,j) for i in [1,2], j in [2,3]]
Out: 2×2 Array{Tuple{Int64,Int64},2}:
(1, 2) (1, 3)
(2, 2) (2, 3)
# 外 中
In : [(i,j) for i in [1,2] for j in [1,2]]
Out: 4-element Array{Tuple{Int64,Int64},1}:
(1, 2)
(1, 3)
(2, 2)
(2, 3)
行列の書き方†
In : [1 2; 3 4]
Out: 2×2 Array{Int64,2}:
1 3
2 4
In : [[1, 2] [3, 4]]
Out: 2×2 Array{Int64,2}:
1 3
2 4
In : [[1 2], [2 3]]
Out: 2-element Array{Array{Int64,2},1}:
[1 2]
[2 3]