這個vec()
是 julia 中的一個內置函數,用於將指定數組重塑為一維列向量,即一維數組。
用法:
vec(a::AbstractArray)
參數:
- a::抽象數組:指定數組。
返回值:它返回重新整形的一維數組。
範例1:
# Julia program to illustrate
# the use of Array vec() method
# Reshaping the specified array as a
# one-dimensional column vector
# i.e, 1D array.
A = ["a", "b", "c", "d"];
println(vec(A))
# Reshaping the specified array as a
# one-dimensional column vector
# i.e, 1D array.
B = ["ab" "bc"; "cd" "df"];
println(vec(B))
# Reshaping the specified array as a
# one-dimensional column vector
# i.e, 1D array.
C = cat(["a" "b"; "c" "d"], ["e" "f"; "g" "h"], ["i" "j"; "k" "l"], dims = 3);
println(vec(C))
輸出:
範例2:
# Julia program to illustrate
# the use of Array vec() method
# Reshaping the specified array as a
# one-dimensional column vector
# i.e, 1D array.
A = [1, 2, 3, 4];
println(vec(A))
# Reshaping the specified array as a
# one-dimensional column vector
# i.e, 1D array.
B = [1 2; 3 4];
println(vec(B))
# Reshaping the specified array as a
# one-dimensional column vector
# i.e, 1D array.
C = cat([1 2; 3 4], [5 6; 7 8], [9 10; 11 12], dims = 3);
println(vec(C))
輸出:
相關用法
- Julia Array reshape()用法及代碼示例
- Julia Array fill()用法及代碼示例
- Julia Array findall()用法及代碼示例
- Julia Array findprev()用法及代碼示例
- Julia Array findnext()用法及代碼示例
- Julia Array findfirst()用法及代碼示例
- Julia Array findlast()用法及代碼示例
- Julia parent()用法及代碼示例
- Julia count()用法及代碼示例
- Julia ndims()用法及代碼示例
- Julia isassigned()用法及代碼示例
- Julia length()用法及代碼示例
- Julia size()用法及代碼示例
- Julia join()用法及代碼示例
- Julia eachindex()用法及代碼示例
- Julia conj!()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Reshaping array as a vector in Julia – vec() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。