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

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 
主站蜘蛛池模板: 峡江县| 夹江县| 武隆县| 泸定县| 海丰县| 长武县| 临潭县| 江安县| 乳山市| 汶上县| 宝应县| 积石山| 大关县| 平度市| 丰城市| 明星| 迭部县| 宁津县| 三门峡市| 同江市| 巴塘县| 泉州市| 庆城县| 尼木县| 沭阳县| 龙陵县| 灌南县| 万宁市| 滦平县| 平乐县| 河津市| 东平县| 枣庄市| 涪陵区| 噶尔县| 鄢陵县| 富顺县| 金堂县| 湟中县| 沧源| 昆山市|