<p>I would like to trim long sequences of the same value from a binary file in python. A simple way of doing it is simply reading in the file and using re.sub to replace the unwanted sequence. This will of course not work on large binary files. Can it be done in something like numpy?</p>

If two copies fit in memory, then you can easily make a copy.  The second copy is the compressed version.  Sure, you can use numpy, but you can also use the
array
package.  Additionally, you can treat your big binary object as a string of bytes and manipulate it directly.
It sounds like your file may be
REALLY
large, and you can't fit two copies into memory.  (You didn't provide a lot of details, so this is just a guess.) You'll have to do your compression in chunks.  You'll read in a chunk, do some processing on that chunk and write it out.  Again, numpy, array or simple string of bytes will work fine.