logankilpatrick
logankilpatrick

Reputation: 14521

How to clear an array in Julia

I have an array representing image metadata that I want to clear out. Currently, I use the empty!() function but it is throwing an error because I think it needs to be a dictionary and I have an array so I am looking for an alternate way to clear the Array.

For reference, here is the type I am working with:

Array{ImageMetadata.ImageMeta{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2,Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2},P} where P<:AbstractDict{Symbol,Any},1}

Upvotes: 5

Views: 3380

Answers (2)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69869

I am not sure what you mean by "clear", but in general you can use fill! to fill the array with a value of your choice.

However, if your question is to make an array filled with some values to be set to have #undef in its entries (if its eltype allows for it), then I do not know of a method to make this. You can use similar to create a new array that will have the same shape and be uninitialized.

Upvotes: 4

pfitzseb
pfitzseb

Reputation: 2554

empty! shouldn't be throwing an error:

julia> x = rand(10);

julia> empty!(x)
0-element Array{Float64,1}

Would be useful to know what error you're actually seeing.

Upvotes: 9

Related Questions