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

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 
主站蜘蛛池模板: 镶黄旗| 雷波县| 浮山县| 济宁市| 大丰市| 黔江区| 即墨市| 鲁甸县| 万州区| 定州市| 昔阳县| 胶南市| 横峰县| 巴林右旗| 即墨市| 孝昌县| 祁阳县| 富锦市| 仙居县| 阿拉善右旗| 文昌市| 巴南区| 定南县| 阜城县| 白朗县| 呼图壁县| 新源县| 洛浦县| 上高县| 西城区| 健康| 通渭县| 孟津县| 翁牛特旗| 韩城市| 南阳市| 云南省| 房山区| 赤壁市| 哈巴河县| 响水县|