juiia常用数组操作代码
代码语言:julia
代码描述:juiia常用数组操作代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
function printsum(a) # summary generates a summary of an object println(summary(a), ": ", repr(a)) end # arrays can be initialised directly: a1 = [1,2,3] printsum(a1) #> 3-element Array{Int64,1}: [1, 2, 3] # or initialised empty: a2 = [] printsum(a2) #> 0-element Array{Any,1}: Any[] # since this array has no type, functions like push! (see below) don't work # instead arrays can be initialised with a type: a3 = Int64[] printsum(a3) #> 0-element Array{Int64,1}: Int64[] # ranges are different from arrays: a4 = 1:20 printsum(a4) #> 20-element UnitRange{Int64}: 1:20 # however they can be used to create arrays thus: a4 = collect(1:20) printsum(a4) #> 20-element Array{Int64,1}: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, #> 15, 16, 17, 18, 19, 20] # arrays can also be generated from comprehensions: a5 = [2^i for i = 1:10] printsum(a5) #> 10-element Array{Int64,1}: [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024] # arrays can be any type, so arrays of arrays can be created: a6 = (Array{Int64, 1})[] printsum.........完整代码请登录后点击上方下载按钮下载查看
网友评论0