Suppose I have:
$a = [
[1, 0, 1]
[0, 1, 0]
[0, 1, 1]
]
and I want to extract all rows where $row[2] == 1
. My resulting piddle would look like:
$b = [
[1, 0, 1]
[0, 1, 1]
]
Is this possible with PDL?
I'm new to PDL
, but it seems like you can use which
result as a mask.
You need to transpose
original variable first, then transpose
it back after using slice
.
pdl> $a = pdl [[1, 0, 1], [0, 1, 0], [0, 1, 1]]
pdl> p which($a(2) == 1)
[0 2]
pdl> p $a->transpose
[
[1 0 0]
[0 1 1]
[1 0 1]
]
pdl> p $a->transpose->slice(which($a(2) == 1))->transpose
[
[1 0 1]
[0 1 1]
]
You need to use
which
to generate a list of indexes of your matrix which have a value of 1 in the third columnand pass this to
dice_axis
, which will select the rows with the given indexes. Axis 0 is the columns and axis 1 is the rows, so the code looks like thisoutput