From a large matrix of around 2000 * 2000 i want to select 2*2 matrix and find minimum of that 2*2 matrix in a loop for the whole matrix.Here is the attachment of file.txt.
1
Expert's answer
2016-01-27T03:55:30-0500
import sys from itertools import tee def infixes2(i): a, b = tee(i) next(b, None) return zip(a, b) m = [] with open(sys.argv[1]) as f: r = [int(x) for x in f.readline().split()] r = [min(x) for x in infixes2(r)] for l in f: n = [int(x) for x in l.split()] c = [] for i in range(len(n)-1): t = r[i] r[i] = min(n[i],n[i+1]) c.append(min(t,r[i])) m.append(c) for r in m: print(" ".join([str(x) for x in r]))
Comments
Leave a comment