Answer to Question #57501 in Python for krishna

Question #57501
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]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS