Selecting Items from an Array or Table - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 17 : Selecting Items from an Array or Table

Selecting Items From an Array or Table

The select, remove, and selectremove commands are ideal for searching for data. The default behaviour of these commands is to return a result object of exactly the same size and dimensions as the one you passed in, with NULL's in place of removed items.  Automatic flattening of NULLs makes the behaviour different in lists compared to Arrays.  

NULL is automatically removed from lists.

l := [1, NULL, 3, NULL, 5];

l:=1,3,5

(1)

 

This is not the case for Arrays.

a := Array(1 .. 5, {1 = 1, 2 = NULL, 3 = 3, 4 = NULL, 5 = 5});

a:=1NULL3NULL5

(2)

 

This paradigm was mirrored in selectremove.

 

select(isprime, [1, 2, 3, 4, 5, 6]);

2,3,5

(3)

select(isprime, <1, 2, 3, 4, 5, 6>);

NULL23NULL5NULL

(4)

 

Now, in Maple 17, you can use an option to force the removal of NULL from arrays and tables. The option, flatten, is noted in square brackets after the command name.

 

select[flatten](isprime, < 1, 2, 3, 4, 5, 6>);

235

(5)

remove[flatten](isprime, table({1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 6 = 6}));

table1&equals;1&comma;4&equals;4&comma;6&equals;6

(6)

Multi-dimensional data is flattened into a one-dimensional array.

 

M := <1, 2, 3; 4, 5, 6>;

M:=123456

(7)

select[flatten](isprime, M);

253

(8)

remove[flatten](isprime, M);

146

(9)

selectremove[flatten](isprime, M);

253&comma;146

(10)

See Also

remove, select, selectremove