I got absolutely stumped at:
indices = numpy.array([b for a in x for b in a if not b==k])
Any pointers on how I should read [b for a in x for b in a if not b==k]
, in the context of x
being a 2D-array of integers and k
being an integer? Or parenthesize it to help me understand the precedence of things?
This is equivalent to:
result = []
for a in x:
for b in a:
if not b == k:
result.append(b)
indices = numpy.array(result)
You can read the list comprehension from left to write and turn them into separate for loops.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With