Message Boards Message Boards

0
|
8426 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

TakeWhile and Select

I have this list:

geo = {{0.107885, 0.21577, 0.313393, 0.411015, 0.499351, 0.587688, 0.667621,
   0.747554, 0.819884, 0.892213, 0.981434, 1.07066, 1.15988, 1.2491, 
  1.33832, 1.42754, 1.51676, 1.60598, 1.6952}}

If I SELECT the elements Lato1 and Lato2, with the the command below, the command sequence runs.

B=0.5
geo = Flatten [geo]
Lato1 = Select [geo, #<=B &] 
Latoo2 = Select[geo , B<#<1.6. &] 

On the contrary if I use the command TakeWhile, it doesen't run for Lato2. Why??

B=0.5
geo = Flatten [geo]
Lato1 = TakeWhile [geo, #<=B &] 
Lato2 = TakeWhile [geo , B<#<1.6. &] 

Thanks

2 Replies

Thank you!

Posted 10 years ago

By definition,

Select[list,crit]

picks out ALL elements of the list for which crit is True.

whereas

TakeWhile[list,crit]

gives elements of the list from the beginning for which crit is True but stops at the value for which crit is not true. It doesn't evaluate further.

For e.g.

Select[{a, 1, 2, 3, b, c, 4, d, 5}, IntegerQ]
{1, 2, 3, 4, 5}

But

TakeWhile[{a, 1, 2, 3, b, c, 4, d, 5}, IntegerQ]
{}
POSTED BY: Girish Arabale
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract