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
|
330 Discussions
|
Please Login in order to post a comment
# 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("]")
import numpy
N = int(input())
ListA = list() ListB = list()
for i in range(N): ListA.append(list(map(int , input().split())))
for j in range(N): ListB.append(list(map(int , input().split())))
A = numpy.array(ListA) B = numpy.array(ListB)
result = numpy.dot(A , B)
print(result)
import numpy as np a = int(input()) element = [] element1= [] for z in range(a): b= input() c= b.split() element.append(c)
for j in range(a): b= input() c= b.split() element1.append(c) element = np.array(element, dtype=int) element1 = np.array(element1, dtype=int) print(np.dot(element,element1))
This is understandable solution from my side