TransWikia.com

How to filter table from some rows without flattening it?

Mathematica Asked on June 16, 2021

Consider the following table:

a1[x_] = If[x < 1.1, 3, Pi/2]
tabb = ParallelTable[{x, y, z, a1[x]}, {x, 1, 2, 0.1}, {y, 
   0.5, 1, 0.1}, {z, 1, 3, 1}]

Here, a1[x] is some function that mimics some realistic functions; in reality, they may depend on other parameters except for x, and change in a different manner than just with x $>1.1$.

The output looks like {{{row,row,…},{row,row,…}},…},…}:

{{{{1., 0.5, 1, 3}, {1., 0.5, 2, 3}, {1., 0.5, 3, 3}}, {{1., 0.6, 1, 
    3}, {1., 0.6, 2, 3}, {1., 0.6, 3, 3}}, {{1., 0.7, 1, 3}, {1., 0.7,
     2, 3}, {1., 0.7, 3, 3}}, {{1., 0.8, 1, 3}, {1., 0.8, 2, 3}, {1., 
    0.8, 3, 3}}, {{1., 0.9, 1, 3}, {1., 0.9, 2, 3}, {1., 0.9, 3, 
    3}}, {{1., 1., 1, 3}, {1., 1., 2, 3}, {1., 1., 3, 3}}}, {{{1.1, 
    0.5, 1, 3}, {1.1, 0.5, 2, 3}, {1.1, 0.5, 3, 3}}, {{1.1, 0.6, 
    1, [Pi]/2}, {1.1, 0.6, 2, [Pi]/2}, {1.1, 0.6, 3, [Pi]/
    2}}, {{1.1, 0.7, 1, [Pi]/2}, {1.1, 0.7, 2, [Pi]/2}, {1.1, 0.7, 
    3, [Pi]/2}}, {{1.1, 0.8, 1, [Pi]/2}, {1.1, 0.8, 2, [Pi]/
    2}, {1.1, 0.8, 3, [Pi]/2}}, {{1.1, 0.9, 1, [Pi]/2}, {1.1, 0.9, 
    2, [Pi]/2}, {1.1, 0.9, 3, [Pi]/2}}, {{1.1, 1., 1, [Pi]/
    2}, {1.1, 1., 2, [Pi]/2}, {1.1, 1., 3, [Pi]/2}}},...}

It has a block-like structure. I would like to exclude rows for which a1 = $pi/2$. I may easily do this using Flatten[tabb,{1,2,3}], but the structure of the table would be destroyed (in general, the table may be much more complicated). Is it possible to remove such rows without destroying the structure of the table?

One Answer

Since you want to test the last element of each {x, y, z, a1[x]}, I'd modify C.E.'s suggestion in the comments to make sure that cases where Pi/2 appears at any other locations don't get thrown away:

DeleteCases[t, {_, _, _, Pi/2}, {3}] /. {} -> Nothing

This pattern first throws away the structure you don't want, and then the replacement drops the resulting {}-s making it cleaner.

Correct answer by ConservedCharge on June 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP