4 ms·
Both are overloaded (__gt__ and __getitem__). My question to you is: How would expect this to be written (in Python)?
by fantod 6y ago
Both are overloaded (__gt__ and __getitem__). My question to you is: How would expect this to be written (in Python)?
- metalrain 6y agoI guess lambda is too verbose a[lambda i: i > 5] = 0 Probably would expect something like this np.set(a, lambda i: i > 5, 0) But that might be too cumbersome when combining values from multiple arrays.
- fantod 6y agoYou made me realize, I think of the brackets as saying "where". vec[2] is vec where the index is 2. vec[vec > 5] is vec where the entries of vec are greater than 5, etc.
- beagle3 6y agoK makes this explicit with the ‘where’ function which converts a Boolean array into the list of indices of true values. Thus, x[4 5 6] is index access (“at”); also x@4 5 6 x[&x>3] is “x at where x is greater than 3” ; can also be written x@&x>3