Message Boards Message Boards

0
|
4415 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

SELECT with variable values

Hi, I have


B = {1.3, 1.5, 1.6, 1.6, 1.7}; 

and


geo = {{0.099, 0.199, 0.286, 0.374, 0.452, 0.529},
            {  0.598, 0.666, 0.75, 0.833, 0.916, 1.},
            { 1.083, 1.166,   1.25, 1.333, 1.4, 1.466}, 
            { 1.533, 1.6, 1.66, 1.73, 1.8, 1.86},{ 1.93, 2., 2.08, 2.166, 2.25, 2.33, 2.41}}

I'd like SELECT in geo[[1]] the values < B[[1]], in geo [[2]] the values < B[[2]], in geo [[3]] the values < B[[3]] and so on. So if i use this command


Select[#, # <= B[[#]] &] & /@ geo   

or

Select[#, # <= B &] & /@ geo 

It doesn't run.

Someone could help me? Please?

Thank you. Margherita

4 Replies

Hi,

Here is a couple of ways to do it:

Table[Select[geo[[i]], # < B[[i]] &], {i, 1, Length[geo]}]
Inner[Select[#1, Function[x, x < #2]] &, geo, B, List]

I.M.

POSTED BY: Ivan Morozov
Posted 11 years ago

Hi,

Below is example code. The Table function looks at each row and selects the elements of that row < the element row[[n]], where n is the index of the row. Note that it assumes it will always find the element m[[n,n]]. If a row is shorter than it's index number, it will fail to do so and generate an error. It will always work with a matrix with the number of rows <= columns. The Select employs a "pure function."

In[3]:= m = Table[RandomInteger[{1, 9}], {i, 5}, {j, 5}];

In[4]:= Table[
 Select[m[[i]], # < m[[i, i]] &],
 {i, Length[m]}
 ]

Out[4]= {{2, 1}, {1}, {3}, {}, {2, 3, 2, 3}}

Best, David

POSTED BY: David Keith

Hi, here is annother short solution:

Re[Select[#, Re[#] > Im[#] &] & /@ (geo + I B)]

Henrik

POSTED BY: Henrik Schachner

Thank you very much.

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