Fill an array with specific values in Julia | Array fill() method
fill() is an inbuilt function in julia which is used to return an array of specified dimensions filled with a specific value passed to it as parameter.
Syntax: fill(Value, Dimension)
- Value: To be filled in the array
- Dimension: Required size of the array
Returns: It returns an array of nXn dimension with each element as the specified value.
Array fill!() method
fill!() method works exactly like
fill() method i.e. it fills an array with a specific value passed to it as argument, but the only difference is that,
fill!() method takes an existing array as argument and fills it with a new specified value. While the
fill() method takes array dimensions and creates a new array of its own.
Syntax: fill!(Array, Value)
- Array: It is the array of specified dimenstion.
- Value: It is the value to be filled in the array.
Returns: It returns the array passed to it as argument with the specified value filled at each index.
Example: Below code is using one dimension array of 3 elements.