why we used mat and not filter? why we didnt used filter[n/2,n/2] instead mat[n/2,n/2]? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why we used mat and not filter? why we didnt used filter[n/2,n/2] instead mat[n/2,n/2]?

import numpy as np def filter_matrix(center,n): filter = -1*np.ones((n,n)) mat[n/2,n/2] = center return mat.tolist() ...by example if i run this code ; filter_matrix (8,3) [[-1,-1,-1],[-1,8,-1],[-1,-1,-1]]

10th Oct 2018, 7:39 AM
sama baluom
sama baluom - avatar
5 Answers
+ 3
I don't know what mat is (and if you to run the program, you'll probably see that python doesn't know that neither) , but if you use it with square brackets, I assume it's the name of a variable/list. It wasn't defined, so you can't use it. filter is not an appropriate name for a variable because there is a built-in function with the same name
10th Oct 2018, 9:33 AM
Anna
Anna - avatar
+ 2
I wasn't able to run your code. I had to change it to import numpy as np def filter_matrix(center,n): filter = -1*np.ones((n,n)) filter[n//2, n//2] = center return filter.tolist() Replacing all occurrences of filter by mat should also work. So could you please explain the question? Also, I think we need // instead of /, so the indices do not become floats.
10th Oct 2018, 9:28 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Kishalaya Saha Anna Hi! ,I don't know what is mat, it's not even defined ,thats why I asked why mat[n/2,n/2] , (was solving a question and found this solution )
10th Oct 2018, 9:48 AM
sama baluom
sama baluom - avatar
+ 2
Anna ,Kishalaya Saha and thanks ☺
10th Oct 2018, 9:56 AM
sama baluom
sama baluom - avatar
+ 2
Maybe sama baluom is looking for the 'map' Function. map (function, list) will apply a Function to all Items of a List.
10th Oct 2018, 11:47 AM
Sebastian Keßler
Sebastian Keßler - avatar