We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Numpy
- Array Mathematics
- Discussions
Array Mathematics
Array Mathematics
Sort by
recency
|
335 Discussions
|
Please Login in order to post a comment
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)
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)
For Python3 Platform
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')