0
$\begingroup$

I have this list

preRowLocalizer[27]={Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, \
Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, {0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   1, 0, 0, 0, 0, 
  0}, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, \
Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, \
Null, Null, Null, Null, Null}

But I want to get only the element of the form

{0,....,0,1,0,...,0}

I tried using the command Select[preRowLocalizer[27], # != Null], but it is not giving me any output. Does anyone know why this is happening?

$\endgroup$
5
  • 2
    $\begingroup$ Use =!= instead of !=, and report back. $\endgroup$ May 29, 2016 at 19:38
  • $\begingroup$ I tried that and it is giving me only an empty set {}. $\endgroup$
    – juyo
    May 29, 2016 at 19:41
  • $\begingroup$ Select[list, # =!= Null &] works for me; what did you put in? $\endgroup$ May 29, 2016 at 19:42
  • $\begingroup$ With the additional & works, do you know why that is needed? $\endgroup$
    – juyo
    May 29, 2016 at 19:44
  • $\begingroup$ Look at the docs for Select[]; pay attention to the "Basic Examples". $\endgroup$ May 29, 2016 at 19:46

1 Answer 1

1
$\begingroup$
First[DeleteCases[preRowLocalizer[27], Null]]

First[preRowLocalizer[27] /. Null -> Nothing]

First[Cases[preRowLocalizer[27], _List]]

All the above give

{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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