ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 30 Jun 2016 17:57:42 +0200Convert all complex numbers in array/matrix to value 0 or remove these numbershttps://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/ 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)?
Thanks for your help!
Rgds
SamSat, 18 Jun 2016 21:39:34 +0200https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/Comment by tmonteil for <p>Hi all</p>
<p>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)?</p>
<p>Thanks for your help!</p>
<p>Rgds
Sam</p>
https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?comment=33849#post-id-33849Could you please provide an example of an array, and the expected result, it is not clear to me. Are all entries complex numbers ?Sun, 19 Jun 2016 17:18:20 +0200https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?comment=33849#post-id-33849Comment by sam_kjm for <p>Hi all</p>
<p>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)?</p>
<p>Thanks for your help!</p>
<p>Rgds
Sam</p>
https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?comment=33854#post-id-338541)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.8859791354693165*I 0.1849665371636101 +0.1317620873508901*I]
[ 2.887006775607812 -0.1147163491731212Mon, 20 Jun 2016 03:57:42 +0200https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?comment=33854#post-id-33854Comment by slelievre for <p>Hi all</p>
<p>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)?</p>
<p>Thanks for your help!</p>
<p>Rgds
Sam</p>
https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?comment=33855#post-id-33855Try editing your question; comments don't leave you enough room to provide enough information.Mon, 20 Jun 2016 10:07:16 +0200https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?comment=33855#post-id-33855Answer by sam_kjm for <p>Hi all</p>
<p>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)?</p>
<p>Thanks for your help!</p>
<p>Rgds
Sam</p>
https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?answer=33980#post-id-33980I 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()Thu, 30 Jun 2016 17:57:42 +0200https://ask.sagemath.org/question/33847/convert-all-complex-numbers-in-arraymatrix-to-value-0-or-remove-these-numbers/?answer=33980#post-id-33980