I am trying to calculate Rij = Aij * Bij/Cij
by Numpy broadcasting.
B1 * np.linalg.inv(C1)
gives a singular matrix error.
I have also tried doing this. It gave me some values but I am not super sure if it is correct.
D = B1 / C1[..., None]
import numpy as np
from numpy.linalg import inv
A = [[(i+j)/2000 for i in range(500)] for j in range(500)]
B = [[(i-j)/2000 for i in range(500)] for j in range(500)]
C = [[((i+1)/(j+1))/2000 for i in range(500)] for j in range(500)]
def numpy_task3_part_A(A,B,C):
A1 = np.array(A)
B1 = np.array(B)
C1 = np.array(C)
D = B1 / C1[..., None]
Rij = A1 @ D
return Rij
A1 = np.array(A)
B1 = np.array(B)
C1 = np.array(C)
print(C1.shape)
print(B1.shape)
print(A1.shape)
numpy_task3_part_A(A,B,C)
How can I solve this issue?