当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Julia vec()用法及代码示例


这个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))

输出:




相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Reshaping array as a vector in Julia – vec() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。