官术网_书友最值得收藏!

Other ways to create arrays

For convenience, zeros(n) returns an n element array with all the elements equal to 0.0, and ones(n) does the same with elements equal to 1.0.

range(start, stop=value, length=value) creates a vector of n equally spaced numbers from start to stop, for example, as follows:

eqa = range(0, step=10, length=5) #> 0:10:40
show(eqa) #> 0:10:40

You can use the following to create an array with undefined values #undef, as shown here:

println(Array{Any}(undef, 4)) #> Any[#undef,#undef,#undef,#undef] 

To fill an array arr with the same value for all the elements, use fill!(arr, 42), which returns [42, 42, 42, 42, 42].

To create a five-element array with random Int32 numbers, execute the following:

v1 = rand(Int32,5) 
5-element Array{Int32,1}: 
  905745764 
  840462491 
 -227765082 
 -286641110 
  16698998 
主站蜘蛛池模板: 杭州市| 新和县| 繁昌县| 谢通门县| 克拉玛依市| 城口县| 永嘉县| 隆德县| 寻乌县| 兴安盟| 贡觉县| 仙居县| 波密县| 阳高县| 平潭县| 岐山县| 西乌| 酉阳| 盐城市| 云南省| 三都| 凌源市| 深圳市| 哈巴河县| 溧水县| 高安市| 都匀市| 唐山市| 沭阳县| 桂林市| 临夏市| 临西县| 太仆寺旗| 万全县| 平凉市| 张掖市| 冷水江市| 龙里县| 枣阳市| 黔西县| 成武县|