I am new in Python and I am facing the following error in the code:
import numpy as np
A = np.empty([2, 2], dtype = float)
Z = np.empty([2, 2], dtype = float)
Z = [[2.0, 0.0], [0.0, 3.0]]
A = [[1, -1], [1, -2]]
print(np.divide(A, np.power(Z, 2)))
These code gives the following result:
[[ 0.25 -inf], [inf -0.22222222]]
But I know, using a calculator, that the correct answer should be:
[[ 0.25 -0.25], [ 0.111111 -0.22222222]]
In short, thhis operation gives me the following error: RuntimeWarning: divide by zero encountered in true_divide
Z = [[2.0, 0.0], [0.0, 3.0]]andA = [[1, -1], [1, -2]]you are settingAandZto type list. I'd rather just initialize the array's usingnp.array([[...], [...]], dtype=float)- Michael Richardson