# Convert all complex numbers in array/matrix to value 0 or remove these numbers This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi all

I'm new to sagemath, approximately 2 week-old. How do you convert all complex numbers in a nested array to value 0 or NaN? Or to remove these numbers from the array/matrix(which is eventually what I want to achieve in the end)?

Rgds Sam

edit retag close merge delete

Could you please provide an example of an array, and the expected result, it is not clear to me. Are all entries complex numbers ?

1)I did a "solve" on 2 nonlinear equations with variables var1 and var2. z = solve 2)I made 2 empty lists : var1_y = [], var2_y = [] then i appended the var 1 and var 2 solutions separately for solution in z: var1_y.append(var1.subs(solution)) var2_y.append(var2.subs(solution)) 3) then I combine them into matrix. How do I delete the rows with complex no? Thx! var1_y2 = matrix(var1_y).transpose() var2_y2 = matrix(var2)y).transpose() A = var1_y2.augment(var2_y2) [ 2 0] [ -1/10 0] [0.5186911103074608 - 0.8859791354693165I 0.1849665371636101 +0.1317620873508901I] [ 2.887006775607812 -0.1147163491731212

Try editing your question; comments don't leave you enough room to provide enough information.

Sort by » oldest newest most voted

I did the following to solve this: 1) after solution and appending to lists, I stack lists into matrix 2) convert type from object to 'float64' 3) start a conditional to convert all terms with imag(x) != 0 into nan 4) do a mask to eliminate all rows(axis=1) that contains any term that gives true to isnan()

more