I have a very large set of 400x400 binary matrices M. For a given binary matrix A, how do I find the matrix B within the set M such that it has the least hamming distance from A?
This is probably a duplicate of this question:
Efficiently find binary strings with low Hamming distance in large set
The fact that your string represents a matrix does not change anything to the hamming distance.
For something fancier, you can also look at this recent paper:
https://www.cas.mcmaster.ca/ashtiani/papers/online-nearest-neighbor.pdf