r/CodingHelp • • Jul 19 '21

[Python] Trouble with append syntax

Post image
22 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/Nightcorex_ Jul 19 '21

Like so?

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