3
$\begingroup$

I have the following list:

{{-1628.11740799393 - 557.339672450634 I}, {-1628.11740799393 + 557.339672450634 I},
 {-920.324284271774 - 1508.13304084624 I}, {-920.324284271774 + 1508.13304084624 I},
 {2107.28351459532}, {2145.53211042304}, {2207.19944421678}, {2289.69932193979},
 {2318.0488541237 - 13.4030555095579 I}, {2318.0488541237 + 13.4030555095579 I}}

I would like to remove the complex numbers (Real & Imaginary parts) from this set and keep the real sets only which are 4 subsets in this case. I really appreciate any help in this regard.

$\endgroup$

3 Answers 3

5
$\begingroup$
alist = {-1628.12 - 557.34 I, -1628.12 + 557.34 I, -920.324 - 
   1508.13 I, -920.324 + 1508.13 I, 2107.28, 2145.53, 2207.2, 2289.7, 
  2318.05 - 13.4031 I, 2318.05 + 13.4031 I}

Cases[alist, Except@_Complex]

{2107.28, 2145.53, 2207.2, 2289.7}

$\endgroup$
4
$\begingroup$

Try Select

list={-1628.12 - 557.34 I, -1628.12 + 557.34 I, -920.324 - 1508.13 I, -920.324 + 1508.13 I, 2107.28, 2145.53, 2207.2, 2289.7,2318.05 - 13.4031 I, 2318.05 + 13.4031 I}

Select[list, Im[#] == 0 &]
(*{2107.28, 2145.53, 2207.2, 2289.7}*)
$\endgroup$
2
  • $\begingroup$ It worked! Thanks so much @Ulrich Neumann... $\endgroup$
    – Naps
    Sep 1, 2021 at 10:21
  • $\begingroup$ You're welcome! $\endgroup$ Sep 1, 2021 at 10:21
3
$\begingroup$

Try DeleteCases:

list={-1628.12 - 557.34 I, -1628.12 + 557.34 I, -920.324 - 1508.13 I,-920.324 + 1508.13 I, 2107.28, 2145.53, 2207.2, 2289.7,2318.05 - 13.4031 I, 2318.05 + 13.4031 I}
DeleteCases[list, _Complex]
(*{2107.28, 2145.53, 2207.2, 2289.7}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.