Converting a PNG image to 2D array
<p>I have a PNG file which when I convert the image to a numpy array, it is of the format that is 184 x 184 x 4. The image is 184 by 184 and each pixel is in RGBA format and hence the 3D array.</p>

<p>This a B&amp;W image and the pixels are either [255, 255, 255, 255] or [0, 0, 0, 255].</p>

<p>I want to convert this to a 184 x 184 2D array where the pixels are now either 1 or 0, depending upon if it is [255, 255, 255, 255] or [0, 0, 0, 255].</p>

<p>Any ideas how to do a straightforward conversion of this.</p>

<p>If there are really only two values in the array as you say, simply scale and return one of the dimensions:</p>

<pre><code>(arr[:,:,0] / 255).astype(int)
</code></pre>

python arrays numpy