I have a ndarray which looks like this example:
JavaScript
x
9
1
[['000' '0.0008303259945444978']
2
['001' '0.001097105216902647']
3
['010' '0.009235959101850126']
4
['011' '0.00047129154937779666']
5
['100' '0.018205469077740434']
6
['101' '0.0013647687750767113']
7
['110' '0.94056678166667']
8
['111' '0.028228298617837884']]
9
I need to pick values from the second column, whose corresponding values in the first column matches particular criteria.
Example criteria: second and third position of the string (in first column) are equal to zero. If this is true, take a copy of the corresponding values in the second column and create new ndarray
with them.
Advertisement
Answer
With a normal comprehension list, you can do:
JavaScript
1
3
1
[j for i, j in arr if i[1]=='0' and i[2]=='0']
2
# ['0.0008303259945444978', '0.018205469077740434']
3
You can change the criteria as required.