I'm still new to linux and learning fast.  The same goes for Python.  I'm just getting my hands dirty with it.  <br><br><div class="gmail_quote">On Tue, Oct 9, 2012 at 7:34 AM, Oren Livne <span dir="ltr"><<a href="mailto:livne@uchicago.edu" target="_blank">livne@uchicago.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">With buffer() I get TypeError: single-segment buffer object expected<br>
<br>
Here's an isolated test case, does it fail on your machine too? (Try to rerun a few times)<br>
<br>
import unittest, numpy as np<br>
from numpy.ma.testutils import assert_equal<br>
from numpy import random<br>
from hashlib import sha1<br>
<br>
class TestHashable(unittest.<u></u>TestCase):<br>
    #-----------------------------<u></u>----------------<br>
    # Test Methods<br>
    #-----------------------------<u></u>----------------<br>
    def test_hashes_of_equal_objects_<u></u>from_slice_are_equal(self):<br>
        '''Test reproducability of hashing boolean rows of a matrix obtained from slicing.'''<br>
        #h = np.mod(np.arange(0, 100).reshape(100, 3), 2)<br>
        h = random.randint(0, 2, (4, 100, 2))<br>
        h = h[:, :, 1].transpose()<br>
        h = h[:, np.arange(0, 3)]<br>
        h = (h == 1)<br>
        print h<br>
        def get_index(h):<br>
            for j in range(1, h.shape[0]):<br>
                if np.all(h[j] == h[0]):<br>
                    return j<br>
            return None<br>
        j = get_index(h)<br>
        assert_equal(h[0], h[j], 'Test objects should be equal, if not, rerun test')<br>
        def hash_array(x): return sha1(buffer(x.view(np.uint8)))<u></u>.hexdigest()<br>
        #def hash_array(x): x.tostring()<br>
        assert_equal(hash_array(h[0]), hash_array(h[j]), 'Hash should be reproducible')<br>
<br>
Thanks,<br>
Oren<div class="HOEnZb"><div class="h5"><br>
<br>
On 10/8/2012 10:44 PM, Kyle Cronan wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I don't think I'm seeing that with my numpy here but maybe try passing<br>
the view to buffer() before hashing?<br>
<br>
-Kyle<br>
<br>
On Mon, Oct 8, 2012 at 10:07 PM, Oren Livne <<a href="mailto:livne@uchicago.edu" target="_blank">livne@uchicago.edu</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear All,<br>
<br>
I have a boolean numpy matrix whose rows 1 and 2 are equal. When I hash them<br>
using astype(uint8), I get equal digests, but different digests if<br>
view(uint8) is used. Why is that, or how can I interrogate the internals of<br>
the arrays to see why this happens? I rather use view(), because it's faster<br>
and requires no additional allocation. In IPython on top of Python 2.7.3.<br>
<br>
h[1]<br>
[ True False False False  True  True False  True  True True]<br>
h[2]<br>
[ True False False False  True  True False  True  True True]<br>
sha1(h[1].astype(uint8)).<u></u>hexdigest(), sha1(h[2].astype(uint8)).<u></u>hexdigest()<br>
('<u></u>bc4ec9b78ad53ce78ae24643d8ff30<u></u>2a9ae03bd0',<br>
'<u></u>bc4ec9b78ad53ce78ae24643d8ff30<u></u>2a9ae03bd0')<br>
sha1(h[1].view(uint8)).<u></u>hexdigest(), sha1(h[2].view(uint8)).<u></u>hexdigest()<br>
('<u></u>887ed6519d5b521fe5181f9329b98c<u></u>65897a6a47',<br>
'<u></u>d8cb41ec47d6e01c25986bbd605d39<u></u>e777e5b4f7')<br>
<br>
Thank you so much,<br>
Oren<br>
<br>
--<br>
A person is just about as big as the things that make him angry.<br>
<br>
______________________________<u></u>_________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/chicago</a><br>
</blockquote>
______________________________<u></u>_________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/chicago</a><br>
</blockquote>
<br>
<br>
-- <br>
A person is just about as big as the things that make him angry.<br>
<br>
______________________________<u></u>_________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/chicago</a><br>
</div></div></blockquote></div><br>