Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I 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.



You 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.


K 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: