Counting Islands In Matrix Of Boolean
First of all, your solution for this task looks pretty elegant, from my point of view. I would just provide minor comments to optimize this code.



Your input data is a boolean matrix, so instead of keeping every value as a byte you can use just one bit. For that purpose you can use bitarray module.



Another point, that you are loading whole matrix to the memory. It can be too expensive in certain circumstances. I can suggest one stream-based solution which will calculate a number of islands in dynamic manner. This method was discussed here.