Array Mathematics

Sort by

recency

|

335 Discussions

|

  • + 0 comments

    This doesn't pass as it doesn't produce the nested arrays of the output, but I wanted to lookup how to create a NumPy array without create an intermediate list in memory. This way below is special to the case where the input is array-like, there is a more general numpy.fromiter as well.

    import numpy as np

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

    a = np.fromstring(input().strip(), sep=' ', dtype=int, count=m)

    b = np.fromstring(input().strip(), sep=' ', dtype=int, count=m)

    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 = np.array([list(map(int, input().split())) for _ in range(N)]) B = np.array([list(map(int, input().split())) for _ in range(N)]) 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 = np.array([input().split() for _ in range(N)], int)
    b = np.array([input().split() for _ in range(N)], int)
    
    print(np.add(a,b))
    print(np.subtract(a,b))
    print(np.multiply(a,b))
    print(np.floor_divide(a,b))
    print(np.mod(a,b))
    print(np.power(a,b).astype(int))
    
  • + 0 comments

    For Python3 Platform

    import numpy
    
    n, m = map(int, input().split())
    A = numpy.array([input().split() for _ in range(n)], int)
    B = numpy.array([input().split() for _ in range(n)], int)
    
    print(A + B)
    print(A - B)
    print(A * B)
    print(A//B)
    print(numpy.mod(A, B))
    print(numpy.power(A, B))
    
  • + 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')