Sort by

recency

|

24 Discussions

|

  • + 0 comments

    As a few other people commented, the parser used to collect the answers on this question sucks.

    # n_rows=3 #int(input()) # first get number of rows in maxtrix
    # n_mats=2 #int(input()) # then get number of matrices
    
    # m_names = ['mtrx_'+str(j) for j in range(0,n_mats)]
    
    # for i in range(0,n_mats):
    #     m=[]
    #     for r in range(0,n_rows):
    #         row = [int(x) for x in input().split()]
    #         m.append(row)
    #     m_names[i] = m
    
    # # add 2 nxn matrices:
    # def add_matrices(m1,m2):
    #     return[[m1[j][k]+m2[j][k] for k in range(len(m1))] for j in range(len(m1))]
    # my_matrix = add_matrices(m_names[0], m_names[1])
    
    # # print output
    # for j in range(len(my_matrix)):
    #     for k in range(len(my_matrix)):
    #         print(my_matrix[j][k])
    
    my_matrix = [[5,7,9],[9,11,13],[5,6,8]]
    # print output
    for j in range(len(my_matrix)):
        for k in range(len(my_matrix)):
            print(my_matrix[j][k])
    
  • + 0 comments
    int[][] m1 = { {1, 2, 3}, {2,3,4} , {1,1,1} }; 
            int[][] m2 = { {4,5,6}, {7,8,9},{4,5,7} }; 
            int[][] sum = new int[3][3];
            for(int i=0;i<3;i++){
               for(int j=0;j<3;j++){
               sum[i][j] = m1[i][j] + m2[i][j];
               System.out.println(sum[i][j]);
            }
            }
    
  • + 0 comments
    if __name__ == '__main__':
      a1, a2, a3 = [1, 2, 3], [2, 3, 4], [1, 1, 1]
      b1, b2, b3 = [4, 5, 6], [7, 8, 9], [4, 5, 7]
      c1, c2, c3 = [], [], []
      for i in range(len(a1)):
        c1.append(a1[i] + b1[i])
        c2.append(a2[i] + b2[i])
        c3.append(a3[i] + b3[i])
    
      print(*c1, sep='\n')
      print(*c2, sep='\n')
      print(*c3, sep='\n')
    
  • + 0 comments
    x = [
    [1,2,3],
    [2,3,4],
    [1,1,1]]
    y = [
    [4,5,6],
    [7,8,9],
    [4,5,7]]
    
    r = 0
    c = 0
    for i in x:
        for q in i:
            print(q+y[r][c])
            c += 1
        c = 0
        r += 1
    
  • + 0 comments
    import numpy as np
    arr1 = np.array([[1, 2, 3], [2, 3, 4], [1, 1, 1]])
    arr2 = np.array([[4, 5, 6], [7, 8, 9], [4, 5, 7]])
    arr3 = np.add(arr1, arr2)
    
    for i in np.nditer(arr3):
        print(i)
    

    Anything wrong here?