Fill an array with specific values in Julia | Array fill() method Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The 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)Parameters: Value: To be filled in the arrayDimension: Required size of the array Returns: It returns an array of nXn dimension with each element as the specified value. Example: Python # Julia program to illustrate # the use of Array fill() method # Creating a 1D array of size 4 # with each element filled with value 5 A = fill(5, 4) println(A) # Creating a 2D array of size 2X3 # with each element filled with value 5 B = fill(5, (2, 3)) println(B) # Creating a 3D array of size 2X2X2 # with each element filled with value 5 C = fill(5, (2, 2, 2)) println(C) Output: 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)Parameters: Array: It is the array of specified dimension.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. Python # Julia program to illustrate # the use of Array fill() method # Creating a 1D array of size 5 Array1 = [1, 2, 3, 4, 5] # Filling array with fill!() Array1 = fill!(Array1, 10) println(Array1) # Creating a 2D array of size 2X2 Array2 = [1 2; 3 4] Array2 = fill!(Array2, 10) println(Array2) # Creating a 3D array of size 2X2X2 Array3 = cat([1 2; 3 4], [5, 6; 7 8], dims=3) Array3 = fill!(Array3, 10) println(Array3) Output: Comment More infoAdvertise with us Next Article Checking for true values in an array in Julia - any() and all() Methods K Kanchan_Ray Follow Improve Article Tags : Julia julia-array Similar Reads Get all array elements with true values in Julia | Array findall() Method The findall() is an inbuilt function in julia which is used to return a vector of indices or keys of the all true values from the specified array A. If such true values are not present in the array, return an empty array. Here values of index or key start from 1 i.e, for index of 1st element is 1, i 2 min read Checking for true values in an array in Julia - any() and all() Methods The any() is an inbuilt function in julia which is used to test whether any elements of the specified boolean collection are true and if any of the input value is 'missing', it will return missing if all non-missing values are false. Syntax: any(itr) Parameters: itr: Specified boolean collection. Re 2 min read Reshaping array dimensions in Julia | Array reshape() Method The reshape() is an inbuilt function in julia which is used to return an array with the same data as the specified array, but with different specified dimension sizes. Syntax: reshape(A, dims) Parameters: A: Specified array. dims: Specified dimension. Returns: It returns an array with the same data 2 min read Check if a specific index of an array contains a value in Julia - isassigned() Method The isassigned() is an inbuilt function in julia which is used to test whether the given index contains a value in the specified array or not. Syntax: isassigned(array, i) Parameters: array: Specified array i: Specified index value Returns: It returns true if the specified index value is present in 2 min read Get previous true value from a given array index in Julia | Array findprev() Method The findprev() is an inbuilt function in julia which is used to return the previous index before or including i of a true element of the specified array A, or returns zero if true value is not found. Here values of index or key start from 1 i.e, for index of 1st element is 1, index of 2nd element is 2 min read Get index of last true value of array in Julia | Array findlast() Method The findlast() is an inbuilt function in julia which is used to return the index or key of the last true value in the specified array. Here values of index or key start from 1 i.e, for index of 1st element is 1, index of 2nd element is 2 and so on. Syntax: findlast(A) or findlast(predicate::Function 2 min read Like