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
- Dot and Cross
- Discussions
Dot and Cross
Dot and Cross
Sort by
recency
|
333 Discussions
|
Please Login in order to post a comment
import numpy N = int(input()) array_A = numpy.array([input().strip().split()[:N] for _ in range(N)], dtype=numpy.int_) array_B = numpy.array([input().strip().split()[:N] for _ in range(N)], dtype=numpy.int_) print(numpy.dot(array_A,array_B))
import numpy as np
n = int(input()) a,b= [],[] for i in range(n): a.append(list(map(int, input().split()))) for j in range(n): b.append(list(map(int, input().split()))) print(np.dot(a,b))
import numpy as np
n = int(input())
a = np.array([list(map(int,(input().strip().split()))) for _ in range(n)]) b = np.array([list(map(int,(input().strip().split()))) for _ in range(n)])
print(a @ b)
# def matrixmultiplicaton(A, B, N):
result= [[0]*N for num in range(N)]
for i in range(N):
for j in range(N):
for k in range(N):
result[i][j] += A[i][k]*B[k][j]
return result
if name == 'main':
N=int(input())
A=[]
for num in range(N):
row=list(map(int, input(). strip(). split()))
A.append(row)
B=[]
for num in range(N):
row=list(map(int, input(). strip(). split()))
B.append(row)
result=matrixmultiplicaton(A, B, N)
print("[", end="")
for i, row in enumerate(result):
print("[" + " ".join(map(str, row)) + "]", end="")
if i==0:
print()
if i < len(result) - 1:
print("", end="")
print("]")