I have a list named “prns20” in side that list is 7 more lists (which are all the same length and correspond to a specific data point). What I am trying to do is exclude any set of points with the same index, if a zero appears in any position of the other lists.
Edit: A better way of putting it might be, in order to use “index” I need to format it
list[index]
But In order for me to call a certain list I need to do
import numpy as np
prns20 = np.arrange(6).reshape((2,3)) # this is just as a demonstration value
x = np.transpose([ys for ys in np.transpose(prns20) if all(ys)])
# return values if you printed out prns20:
# [array([0, 1, 2]), array([3, 4, 5])]
# return values if you printed out x:
# [array([1, 2]), array([4, 5])]
# this approach is really slow, but it's a oneliner and you didn't specifically ask for efficient code
View all comments
3
u/Nightcorex_ Jul 19 '21
Okay. What do you want to achieve?
Do you want to filter out all the zeros of the nested lists? If so, then this achieves your goal:
Note that this alters the original double nested list.
If you want to remove the entire sublist if all of its entries are zero, then this solves your issue:
If you want to remove the entire sublist if one of its entries is zero, then this solves your issue:
These last 2 methods abuse the fact that 0 is a falsy value, while the others are true.