Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if an array is empty in Julia?

Tags:

julia

I am trying to see if there's a handy way to check if an array in Julia is empty or not.

like image 983
logankilpatrick Avatar asked Sep 19 '19 12:09

logankilpatrick


People also ask

How do you fill an array in Julia?

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.

Are arrays mutable in Julia?

Arrays in Julia are mutable and hence it allows modification of its content. Elements in arrays can be removed or updated as per requirement.


1 Answers

In Julia you can use the isempty() function documented here.

julia> a = []
0-element Array{Any,1}

julia> isempty(a)
true

julia> length(a)
0

julia> b = [1]
1-element Array{Int64,1}:
 1

julia> isempty(b)
false

Note that I included the length check as well in case that will help your use case.

like image 90
logankilpatrick Avatar answered Sep 19 '22 15:09

logankilpatrick