fill(x, dims)

Create an array filled with the value x. For example, fill(1.0, (10,10)) returns a 10x10 array of floats, with each element initialized to 1.0.

If x is an object reference, all elements will refer to the same object. fill(Foo(), dims) will return an array filled with the result of evaluating Foo() once.


julia> fill(3, 1)
1-element Array{Int64,1}:

Referencing another collection

 julia> foo = [1,2];
 julia> bar = fill(foo, 1, 2)
 1x2 Array{Array{Int64,1},2}:
  [1,2]     [1,2]
 julia> foo[1] = 42;
 julia> bar
 1x2 Array{Array{Int64,1},2}:
 [42,2]     [42,2]

Using functions

julia> function Foo()
julia> fill(Foo(), 1)
1-element Array{Int64,1}:

See Also

Array, broadcast, cat, combinations, conj!, digits!, fieldnames, fill, fill!, last, length, maximum, minimum, ones, parent, parentindexes, partitions, permutations, pointer, pointer_to_array, promote_shape, rand!, reshape, scale, similar, sum, sum_kbn, takebuf_array, transpose!, vec, zeros,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: