precision of drange

If I do:
t1=datetime.datetime(2008,06,02,01,0,0)
t1=datetime.datetime(2008,06,02,02,0,0)
tVec1=drange(t1,t2,datetime.timedelta(seconds=1))
tVec2=drange(t1,t2,datetime.timedelta(seconds=5))
tVec3=nan*ones(tVec1.shape)

I cannot do something like:
for i in tVec2:
tVec3[where(tVec1==i)]=i

tVec3[0] is written, yet the others are not.

print tVec1[0]
> 733195.083333

print tVec1
>[ 733195.08333333 733195.08334491 733195.08335648 ..., 733195.50376352
733195.5037751 733195.50378667]

There is more precision in the second statement and, I believe, the result for no matches inside the for loop.
Is this the desired behavior?

I can do:
vec1=arange(0,100,1)
vec2=arange(0,100,5)
vec3=nan*ones(tVec1.shape)
for i in vec2:
vec3[where(vec1==i)]=i

thanks,
Brian

···

--
Brian E. McLaughlin
Oceanographic Research Specialist
Department of Oceanography
School of Ocean and Earth Science and Technology
University of Hawaii at Manoa
Honolulu, HI 96822
--
e:bem@...2028...
p:808.956.7625
f:808.956.9516
--

Brian McLaughlin wrote:

If I do:
t1=datetime.datetime(2008,06,02,01,0,0)
t1=datetime.datetime(2008,06,02,02,0,0)
tVec1=drange(t1,t2,datetime.timedelta(seconds=1))
tVec2=drange(t1,t2,datetime.timedelta(seconds=5))
tVec3=nan*ones(tVec1.shape)

I cannot do something like:
for i in tVec2:
tVec3[where(tVec1==i)]=i

You don't need the "where", but you do need something like this:

tVec3[fabs(tVec1 - i) < 1e-6]=i

Using perfect equality in floating point comparisons is usually wrong.

Eric

···

tVec3[0] is written, yet the others are not.

print tVec1[0]
> 733195.083333

print tVec1
>[ 733195.08333333 733195.08334491 733195.08335648 ..., 733195.50376352
733195.5037751 733195.50378667]

There is more precision in the second statement and, I believe, the result for no matches inside the for loop.
Is this the desired behavior?

I can do:
vec1=arange(0,100,1)
vec2=arange(0,100,5)
vec3=nan*ones(tVec1.shape)
for i in vec2:
vec3[where(vec1==i)]=i

thanks,
Brian