title: Binary matrix multiplication
body: <p>I got a matrix <em>A</em>, with the following bytes as rows:</p>
  
  <pre><code>11111110  (0xfe)
  11111000  (0xf8)
  10000100  (0x84)
  10010010  (0x92)
  </code></pre>
  
  <p>My program reads a byte from stdin with the function <code>sys.stdin.read(1)</code>. Suppose I receive the byte <em>x</em> <code>10101010 (0xaa)</code>. Is there a way using numpy to perform the multiplication:</p>
  
  <pre><code>&gt;&gt;&gt; A.dot(x)
  0x06 (00000110)
  </code></pre>
  
  <p>As <code>A</code> is a 4x8 matrix, compossed by 4 bytes as rows, and <code>x</code> is an 8 bit array, I was expecting to receive the (nibble <code>0110</code>) byte <code>0000 0110</code> as a result of the multiplication <code>A * x</code>, treating bits as elements of the matrix. </p>
  
  <p>If the elements of the matrix were treated as binary bytes, the result would be:</p>
  
  <pre><code>&gt;&gt;&gt; A = np.array([[1,1,1,1,1,1,1,0],[1,1,1,1,1,0,0,0],[1,0,0,0,0,1,0,0],[1,0,0,1,0,0,1,0]])
  &gt;&gt;&gt; x = np.array([1,0,1,0,1,0,1,0])
  &gt;&gt;&gt; A.dot(x)%2
  array([0, 1, 1, 0])
  </code></pre>