Array Mathematics

Sort by

recency

|

331 Discussions

|

  • + 0 comments

    import numpy as np

    n = int(input().split()[0])

    a, b = [np.array([input().split() for _ in range(n)], int) for _ in range(2)]

    print(np.add(a, b), np.subtract(a, b), np.multiply(a, b), np.floor_divide(a, b), np.mod(a, b), np.power(a, b), sep='\n')

  • + 0 comments
    import numpy as np
    N,M = map(int,input().split())
    A = np.array([input().split() for _ in range(N)],int)
    B = np.array([input().split() for _ in range(N)],int)
    print(A+B)
    print(A-B)
    print(A*B)
    print(A//B)
    print(A%B)
    print(A**B)
    
  • + 0 comments

    import numpy as np

    n, m = map(int, input().split())

    A = [list(map(int, input().split())) for _ in range(n)]

    B = [list(map(int, input().split())) for _ in range(n)]

    a = np.array(A) b = np.array(B)

    print(a + b) print(a - b) print(a * b) print(a // b) print(a % b) print(a ** b)

  • + 1 comment

    My compact solution…

    import sys
    import numpy as np
    
    _ = input()  # We don't need N or M.  Skip them!
    a, b = np.split(np.loadtxt(sys.stdin, int), 2)
    
    print(a + b, a - b, a * b, a // b, a % b, a**b, sep='\n')
    
  • + 0 comments
    # Dimension
    inp = input()
    n, m = map(int, inp.split(' '))
    # print(n,m)
    
    # Arr
    A = input()
    B = input()
    a= numpy.array([ list(int(num) for num in A.split(' ')) ])
    b= numpy.array([ list(int(num) for num in B.split(' ')) ])
    # print(a, b)
    
    # Operation
    print(numpy.add(a,b))
    print(numpy.subtract(a,b))
    print(numpy.multiply(a,b))
    print(numpy.floor_divide(a,b))
    print(numpy.mod(a,b))
    print(numpy.power(a,b))