Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy import *
- import scipy.optimize
- import itertools
- file_data = open('b1.txt','r')
- n = int(file_data.readline())
- inp = []
- for line in file_data.readlines():
- line = line.replace('\n', '')
- t = line.split('\t')
- inp.append(list(map(int, t)))
- matrix = []
- ans = []
- for i in range(n*n):
- t = [0 for k in range(n*n)]
- matrix.append(t)
- ans.append(0)
- for i in range(n):
- for j in range(n):
- for dx in range(-1,2):
- for dy in range(-1,2):
- if 0 <= i+dx < n and 0 <= j+dy < n:
- ans[n*i+j] = inp[i][j]
- matrix[n*i+j][n*(i+dx)+(j+dy)] = 1
- matrix = array(matrix)
- ans = array(ans)
- #data = scipy.optimize.lsq_linear(matrix, ans, bounds=(0, 100), tol=1e-10)
- data = linalg.solve(matrix, ans)
- file_out = open("ans.txt", 'a')
- k = 0
- for i in range(n):
- line = ""
- for j in range(n):
- line += str(int(data[k])) + ' '
- k += 1
- line += '\n'
- file_out.write(line)
- file_out.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement