How can I add two elements of same indices of two 2D arrays in python? -


i tried solve zip function , loop:

mat_c=[[] in range(no_of_rows_c)] in range(no_of_rows_c):     j in range(no_of_columns_c):         mat_c=[a+b (a,b) in zip(mat_a,mat_b)] in range(no_of_rows_c):     j in range(no_of_columns_c):         print(mat_c[i][j]) 

numpy useful kind of thing. in particular, addition of numpy arrays performed element-wise.

mat_a = np.asarray(mat_a) mat_b = np.asarray(mat_b) mat_c = mat_a + mat_b print(mat_c) 

without numpy,

mat_c = [[a+b a,b in zip(row_a, row_b)] row_a, row_b in zip(mat_a, mat_b)] 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -