Selecting Items from an Array or Table - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

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}{:=}\left[{1}{,}{3}{,}{5}\right]$ (1)

This is not the case for Arrays.



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

This paradigm was mirrored in selectremove.

 > select(isprime, [1, 2, 3, 4, 5, 6]);
 $\left[{2}{,}{3}{,}{5}\right]$ (2)
 > select(isprime, <1, 2, 3, 4, 5, 6>);

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>);
 > remove[flatten](isprime, table({1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 6 = 6}));
 ${\mathrm{table}}\left(\left[{1}{=}{1}{,}{4}{=}{4}{,}{6}{=}{6}\right]\right)$ (3)



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

 > M := <1, 2, 3; 4, 5, 6>;
 > select[flatten](isprime, M);
 > remove[flatten](isprime, M);
 > selectremove[flatten](isprime, M);