I have 2 arrays of tuples and I have a loop asking if one element is in the other. At each step I ask if the tuple contained in the coord array is in the Y array. The loop works fine except for one element which I cant explain why. Here is what I have :
Y[55:65] # This is the array I want to check at each step if my state is in or not.
11-element Array{Any,1}: (2.0, 1.0) (3.0, 1.0) (4.0, 1.0) (5.0, 1.0) (6.0, 1.0) (7.0, 1.0) (8.0, 1.0) (9.0, 1.0) (10.0, 1.0) (11.0, 1.0) (12.0, 1.0)
coord[i-1] # this is one element of coord that is in Y
0-dimensional Array{Tuple{Float64,Float64},0}: (6.0, 1.0)
coord[i] # this is an other element of coord that is in Y
0-dimensional Array{Tuple{Float64,Float64},0}: (7.0, 1.0)
But then when I test when they are in Y:
in(coord[i],Y[55:65]) # testing if coord[i] is in Y
false
in(coord[i-1],Y[55:65]) # testing if coord[i-1] is in Y
true
I dont understand: they are both represented in the same way in Y, they have the same type, why do I get from using in() that one is in and not the other?
I use Julia version 0.6.3.
Thanks in advance for the help!
Y[55:65]
contains(7.0, 1.0)
wrapped in an 0-dimensional array and(6.0, 1.0)
is not wrapped. They get printed in the same way so it is hard to distinguish them using visual inspection only. But this might be the case asY[55:65]
is aVector{Any}
so it seems that it contains mixed types. Can you post the result oftypeof.(Y[55:65])
? – Bogumił Kamińskitypeof.(Y[55:65])
gives :11-element Array{DataType,1}: Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0} Array{Tuple{Float64,Float64},0}
– ChrlTsrY[60] == coord[i]
comparison return? If it isfalse
then whatY[60][][1] == coord[i][][1]
andY[60][][2] == coord[i][][2]
return? If any of these two returnfalse
then actually entries of the tuples are not equal (which can happe if you are working withFloat64
due to rounding). – Bogumił Kamiński