I'd like to check if my vector / array is made of numbers.
I've tried:
if isa(x, Array{Number})
println("yes")
end
But it doesn't seem to work...
You have two scenarios here.
Scenario 1. You want to check if type of a vector allows only numbers. Then write:
eltype(x) <: Number
Scenario 2. You want to check if actually all elements of a vector are numbers. Then write:
all(isa.(x, Number))
The second is less efficient because it has to check the whole array. The reason why it might be sometimes needed is that you can have e.g.:
x = Any[1, 2, 3]
which contains only numbers, but type of the vector in general allows it to contain other things than numbers (so it will fail scenario 1 but pass scenario 2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With