println("hello!")
println("hello!")
print("hello!")
print("hello!")
hello!
hello!
hello!hello!
二つの機能の違いを包みます。
using Pkg
abstract type Real <: Number end
レアルの数のサブクラスであります
(1+2)::Int
::
シンボルタイプ宣言のpython3のように:
、等def uniquePaths(self, m: int, n: int) -> int:
::
オペレータは、プログラムタイプの注釈に追加の変数や式に使用することができます。
指定された型の例は、しましょうパラメータ、
#指定参数 M 为Matrix类型,这里T是参数模板比如整数Int,Float64等,T <: Number表示参数得是Number子类型
function restructure_matrix(M::Matrix{T}) where {T <: Number}
#Matrix其实是二维数组
Matrix
Array{T,2} where T
#Vector是维数为1的数组
Vector
Array{T,1} where T
例は、の値が指定された型で返してみましょう、
function sinc(x)::Float64
if x == 0
return 1
end
return sin(pi*x)/(pi*x)
end
軽く裁判、
文字列、シンボルと辞書
sym = Symbol("haha") #:haha
str = String("haha") #"haha"
dic = Dict([("C",7),("D",8),("A", 3), ("B", 2),("E",1)])
tem =keys(dic)
typeof(tem) #Base.KeySet
collect(tem)
typeof(collect(tem)) #Array{String,1}
collect(dic)
sort(collect(dic)) #按键排序
dic["B"]
dic[collect(keys(dic))[1]] #取字典第一个元素,字典键是无序(不按你加入顺序)的且“B”为第一个
sort(collect(keys(dic))) #这时A才在前
#collect后是Pair的向量
dic
Dict{String,Int64} with 5 entries:
"B" => 2
"A" => 3
"C" => 7
"D" => 8
"E" => 1
collect(dic)
5-element Array{Pair{String,Int64},1}:
"B" => 2
"A" => 3
"C" => 7
"D" => 8
"E" => 1
例では、複合型のメンバー型を宣言し、
struct Foo
bar #默认Any类型
baz::Int
qux::Float64
end
#摸索一下
typeof(Foo)
Foo.bar #type DataType has no field bar
a = Foo(1,2,3)
#atom ctrl+/注释 atom 选中提示 设为 enter
typeof(a) #Foo
a.bar
a.baz
非常に重要なの配列、;
別の行、行数を増やし、互いにスペース、列の数を増やし、numpyの対応np.r_[]
とnp.c_[]
公式声明は、最初の次元と二次元を高めることであることを忘れやすい、総括するには良い時間がある(、どのどこエッジの数、あなたを知っている、明確ではありません。)
Xtest = [0 4 1;
2 2 0;
1 1 1]
3×3 Array{Int64,2}:
0 4 1
2 2 0
1 1 1
その他の例については、実行している、説明する時間は、それについて考えるません、我々は(表情で長い時間のための廃棄物は、記録のためにこれを覚えている)ことを知っています
[1 3 2 4]
[[1 3] [2 4]]
1×4 Array{Int64,2}:
1 3 2 4
[1 ;3; 2; 4]
[1 ,3 ,2, 4]
[[1, 3] ;[2, 4]]
4-element Array{Int64,1}:
1
3
2
4
[1 3; 2 4]
[[1 3] ;[2 4]]
2×2 Array{Int64,2}:
1 3
2 4
[[1 ,3] [2 ,4]] #[[1, 3] ;[2, 4]] add row
2×2 Array{Int64,2}:
1 2
3 4
Pythonの例を添付し、
np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
[[1 2 3 0 0 4 5 6]]
np.c_[np.array([1,2,3]), np.array([4,5,6])]
[[1 4]
[2 5]
[3 6]]
np.r_[np.array([1,2,3]), np.array([4,5,6])]
[0 1 2 3 4 5]
np.r_[np.array([1,2,3]), 0, 0, np.array([4,5,6])]
[1 2 3 0 0 4 5 6]
上記ビットは、2次元アレイ状に、失われる可能性が法律、クリアラ
x= np.c_[np.array([11,12]), np.array([14,15])]
y = np.arange(4).reshape(2,2)
y
array([[0, 1],
[2, 3]])
x
array([[11, 14],
[12, 15]])
np.c_[x,y] #列数增加
array([[11, 14, 0, 1],
[12, 15, 2, 3]])
np.r_[x,y] #行数增加
array([[11, 14],
[12, 15],
[ 0, 1],
[ 2, 3]])
複合タイプ
#复合类型 Composite Types
julia>
julia> foo = Foo("Hello, world.", 23, 1.5)
Foo("Hello, world.", 23, 1.5)
julia> typeof(foo)
Foo
#类型联合
julia> IntOrString = Union{Int,AbstractString}
Union{Int64, AbstractString}
julia> 1 :: IntOrString
1
julia> "Hello!" :: IntOrString
"Hello!"
julia> 1.0 :: IntOrString
ERROR: TypeError: in typeassert, expected Union{Int64, AbstractString}, got Float64
#有参数复合类型 Parametric Composite Types
julia> struct Point{T}
x::T
y::T
end
#NTuple{N,T} is a convenient alias for Tuple{Vararg{T,N}}, i.e. a tuple type containing exactly N elements of type T.