3
$\begingroup$

I tried very hard to find an answer to a trivial problem: which is to delete the rows with Complex Numbers. I tried the following but none worked for me.

deneme = {{-0.01, .4}, {-0.47, -0.054}, {-0.82, -0.07}, {-1.55, -0.08}, {0.10 + 3.14 I, -0.03}, {-0.54, -0.051}, {0.03, 0.10 + 3.14 I}};
DeleteCases[deneme, {I ..}]
DeleteCases[deneme, {Complex ..}]
Cases[deneme, Cases[deneme, Except@{Complex ..}]]
Pick[deneme, Unitize[Abs[deneme].ConstantArray[1., 2]], 1]

I wonder why it is so difficult to find an answer to this problem.

$\endgroup$
  • 2
    $\begingroup$ Select[deneme, VectorQ[#, Element[#, Reals] &] &] $\endgroup$ – Alan Dec 17 '19 at 0:51
  • 1
    $\begingroup$ @Alan No need VectorQ This is just fine Select[deneme, Element[#, Reals] &] $\endgroup$ – OkkesDulgerci Dec 17 '19 at 3:12
8
$\begingroup$
DeleteCases[deneme, {___, _Complex, ___}]

{{-0.01, 0.4}, {-0.47, -0.054}, {-0.82, -0.07}, {-1.55, -0.08}, {-0.54, -0.051}}

Select[FreeQ[_Complex]] @ deneme

{{-0.01, 0.4}, {-0.47, -0.054}, {-0.82, -0.07}, {-1.55, -0.08}, {-0.54, -0.051}}

Cases[_?(FreeQ[_Complex])]@deneme

{{-0.01, 0.4}, {-0.47, -0.054}, {-0.82, -0.07}, {-1.55, -0.08}, {-0.54, -0.051}}

|improve this answer|||||
$\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.