Python Lab

(Matrices and File I/O) Write a Python script named cluster_counter.py that takes command line arguments. The first argument will be a filename. The file loaded will contain an n by m matrix of different characters. This n by m matrix denotes different clusters where each same character represents a group. Casing is not important (i.e A and a are the same group). Touching characters (meaning adjacent and diagonal) of the same group are assumed to be in the same cluster. Write a program that tells the user how many groups exist and for each group, how many sub clusters exist.  (20 points)
Example file test.m
A B A A A
A B A A A
B B A A A
python cluster_counter.py test.m
You have 2 groups: A, B
The Number of clusters are listed below
A : 2
B : 1

Leave a Reply

Your email address will not be published. Required fields are marked *