# I Used NumPy to Impress My Crush- Solved a Math Question

The math required 169 different calculations!

The assignment was on using a **high pass filter **to the given data set. We were using the filter for remote sensing purposes.

Our teacher taught us using a 3*3 data set and gave us 15*15 for the assignment(as expected).

When the assignment submission deadline came close, everyone started panicking. How on earth we will calculate 13*13(one row and column get rejected) rows and columns!!

With everyone, my crush also started panicking. She is the topper of the class.

We all were talking in the group chat about what could we do. At some point, I told, “Don’t worry everyone, there should be software for this type of calculation.”

In reply, my friend(crush) said, “Why don’t you build one with python, Sorower?”

I didn’t reply anything because I thought she is right. I recently learned NumPy from an amazing youtube video. So, I thought why shouldn’t I try once.

I started to solve the question without moving an inch. After 6 hours I was able to program the solution with 169 different calculations!

I immediately told everyone and send them the Github link. She was amazed seeing all the calculations and results are nicely shown in the code’s output.

# Code:

**import** **numpy** **as** **np**

*# loading files*

a = np.array([[10,9,20,25,26,34,35,11,20,25,31,32,35,36,28],[76,34,11,15,41,42,77,14,30,24,22,11,16,69,70],[47,25,13,11,10,55,41,39,42,65,27,79,18,20,35],[42,19,15,19,22,52,71,56,34,35,41,50,55,11,38],[34,20,16,60,27,85,35,17,25,16,10,31,52,13,40],[25,30,29,23,18,49,38,78,19,29,18,26,85,12,41],[30,42,20,13,57,23,73,74,60,20,57,63,82,19,71],[19,60,45,28,40,11,79,32,48,45,51,72,42,21,36],[64,36,55,58,38,13,80,28,64,55,61,44,49,32,37],[36,70,31,62,15,15,70,58,76,66,40,13,23,42,72],[70,68,22,14,75,19,36,62,47,59,38,71,11,50,34],[68,43,27,39,54,60,37,52,36,80,15,53,19,51,72],[43,48,41,56,46,16,72,21,70,23,75,33,60,59,73],[60,64,10,17,51,18,34,49,68,67,54,37,13,75,79],[48,76,18,78,61,82,72,69,43,73,46,12,15,25,80]])

q = f'''given dataset:

**{**a**}**'''

print(q)

b = np.array([[1,-2,1],[-2,5,-2],[1,-2,1]])

final_result =[]

print("Calculation: ")

u= 0

**for** m,n **in** zip(range(0,13),range(3,16)):

**for** i,j **in** zip(range(0,13),range(3,16)):

l = a[m:n,i:j] * b

w = np.sum(l)

u= u+1

final_result.append(w)

c = a[m:n,i:j]

e = f'''**{**u**}**th DN value change operation:

'''

print(e)

t = f'''= [(**{**c[0,0]**}** × **{**b[0,0]**}**) + (**{**c[0,1]**}** × **{**b[0,1]**}**) + (**{**c[0,2]**}** × **{**b[0,2]**}**) + (**{**c[1,0]**}** × **{**b[1,0]**}**) + (**{**c[1,1]**}** × **{**b[1,1]**}**) + (**{**c[1,2]**}** × **{**b[1,2]**}**) + (**{**c[2,0]**}** × **{**b[2,0]**}**) + (**{**c[2,1]**}** × **{**b[2,1]**}**) + (**{**c[2,2]**}** × **{**b[2,2]**}**)]

= (**{**l[0,0]**}**) + (**{**l[0,1]**}**) + (**{**l[0,2]**}**) + (**{**l[1,0]**}**) + (**{**l[1,1]**}**) + (**{**l[1,2]**}**) + (**{**l[2,0]**}**) + (**{**l[2,1]**}**) + (**{**l[2,2]**}**)

= **{**w**}**

'''

print(t)

final_array = np.array(final_result)

s = final_array.reshape((13,13))

k = f'''final 13*13 result:

**{**s**}**'''

print(k)

The GitHub link: https://github.com/soorower/JBA_gis_assignment.git

Check “Practice NumPy.ipynb” there.

# Output:

169th number calculation is shown here. Check the Github link to see all.

**At least learning NumPy helped me solving my real-life problem**. I learn a lot in those 6 hours than in any tutorial.

So, my suggestion to the beginner will be,

“Watch one tutorial, then start to solve your/others real life problems. You will feel far more confident than solving a previously set up problem from the internet.”

Quote my words. You will thank me later. Thank you for reading.