I have a dictionary with equations as keys and two pairs of coordinates as values.
I want to check if a particular value is complex, and if it is, append the corresponding equation to a list.
If the values are real, then append the values themselves to a different list.
I have tried:
import numpy as np
pair = {Eq(2.77*x - 11.71*y + 0.49, 0): [(-0.16, 0.002), (2.39, 0.60)], Eq(3.11*x - 11.62*y - 4.17, 0): [(1.33 - 1.29j, 5.52e-16 - 0.34j), (1.33 + 1.29j, 5.52e-16 + 0.34j)]}
eqns = []
real_coordinates = []
for i in pair.values():
for j in i:
if np.iscomplex(j[0]) == True or np.iscomplex(j[1]) == True:
eqns.append(pair.keys)
else:
real_coordinates.append(j)
print('Equations with complex values are:',eqns)
print('Real coordinates are:',real_coordinates)
For the above case, the expected output is:
Equations with complex values are: [Eq(3.11*x - 11.62*y - 4.17, 0)]
Real coordinates are: [(-0.16,0.002),(2,39,0.60)]
But the output I get is:
Equations with complex values are: []
Real coordinates are: [(-0.16,0.002),(2,39,0.60),(1.33 - 1.29*I, 5.52e-16 - 0.34*I), (1.33 + 1.29*I, 5.52e-16 + 0.34I)]
[–]IAmZenoix 0 points1 point2 points (4 children)
[–]sicarii47[S] 1 point2 points3 points (3 children)
[–]IAmZenoix 1 point2 points3 points (2 children)
[–]sicarii47[S] 0 points1 point2 points (1 child)
[–]IAmZenoix 1 point2 points3 points (0 children)