Created
May 26, 2020 08:51
-
-
Save neogeogre/d82a2714b8bc27cb05ed893289e8889f to your computer and use it in GitHub Desktop.
two dimentional interpolation in matrix values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.interpolate import interp2d | |
def matrix_interp(): | |
mat = numpy.array([[70.45, 0, 21.78, 0], | |
[0, 0, 0, 0], | |
[105.12, 0, 1000.45, 0], | |
[0, 0, 0, 0]]) | |
ix = numpy.where(mat != 0) | |
f = interp2d(ix[0], ix[1], mat[ix].flatten(), kind='linear') | |
mat2 = mat.copy() | |
mat2[mat == 0] = f(range(4), range(4)).T[mat == 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment