[Chicago] sha1 of equal arrays different?

Sunah Suh sunah at sunahsuh.com
Tue Oct 9 07:19:23 CEST 2012


Welp, I just tried to reproduce your behavior in the repl and.. got sha1
digests that were identical to the ones that you get when you use astype:
>>> row1
array([ True, False, False, False,  True,  True, False,  True,  True,
 True], dtype=bool)
>>> row2
array([ True, False, False, False,  True,  True, False,  True,  True,
 True], dtype=bool)
>>> hashlib.sha1(row1.view(numpy.uint8)).hexdigest(),
hashlib.sha1(row2.view(numpy.uint8)).hexdigest()
('bc4ec9b78ad53ce78ae24643d8ff302a9ae03bd0',
'bc4ec9b78ad53ce78ae24643d8ff302a9ae03bd0')

Maddening, isn't it? If it helps, that was with the 2.7.2 version that
ships with os x mountain lion and numpy 1.6.1

-S


On Mon, Oct 8, 2012 at 10:44 PM, Kyle Cronan <kyle at pbx.org> wrote:

> I don't think I'm seeing that with my numpy here but maybe try passing
> the view to buffer() before hashing?
>
> -Kyle
>
> On Mon, Oct 8, 2012 at 10:07 PM, Oren Livne <livne at uchicago.edu> wrote:
> > Dear All,
> >
> > I have a boolean numpy matrix whose rows 1 and 2 are equal. When I hash
> them
> > using astype(uint8), I get equal digests, but different digests if
> > view(uint8) is used. Why is that, or how can I interrogate the internals
> of
> > the arrays to see why this happens? I rather use view(), because it's
> faster
> > and requires no additional allocation. In IPython on top of Python 2.7.3.
> >
> > h[1]
> > [ True False False False  True  True False  True  True True]
> > h[2]
> > [ True False False False  True  True False  True  True True]
> > sha1(h[1].astype(uint8)).hexdigest(),
> sha1(h[2].astype(uint8)).hexdigest()
> > ('bc4ec9b78ad53ce78ae24643d8ff302a9ae03bd0',
> > 'bc4ec9b78ad53ce78ae24643d8ff302a9ae03bd0')
> > sha1(h[1].view(uint8)).hexdigest(), sha1(h[2].view(uint8)).hexdigest()
> > ('887ed6519d5b521fe5181f9329b98c65897a6a47',
> > 'd8cb41ec47d6e01c25986bbd605d39e777e5b4f7')
> >
> > Thank you so much,
> > Oren
> >
> > --
> > A person is just about as big as the things that make him angry.
> >
> > _______________________________________________
> > Chicago mailing list
> > Chicago at python.org
> > http://mail.python.org/mailman/listinfo/chicago
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>



-- 
Sunah Suh
Software Engineer @ Etsy
Full-Stack Web Developer, Pythonista, Jill-of-all-trades
Intermittent Winner in Life
Website: sunahsuh.com | GChat: sunah at sunahsuh.com
Check my current email load: http://courteous.ly/d7mWb4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20121009/6c1be8a6/attachment.html>


More information about the Chicago mailing list