Https://jovian.ml/shivani12600/numpy-array-operations

I’ve a doubt
sum([x for x in arr if x>0])
is exactly same as
sum(x for x in arr if x>0)
that is square bracket not required
but
len([x for x in arr if x>0])
is not same as
len(x for x in arr if x>0)
here if we remove square bracket it throws an error

You can simply check the type of the result in both ways first
type([x for x in arr if x>0]) = list => you’re doing list comprehension

type([x for x in arr if x>0]) = generator

FYI,
List will have all values saved in memory before perform any operation, on other hand Generator will provide one bye one and which will not consume any larger memory, it re uses the previous.
Normally we use generator when we won’t re-use the values more than single use, if the values are needed in more than one, better to save that in a list and use whenever needed.

Better checkout official documentation regarding this: Python Generators