Python equivalent of which() in R

前端 未结 3 942
清歌不尽
清歌不尽 2020-12-28 15:33

I am trying to take the following R statement and convert it to Python using NumPy:

1 + apply(tmp,1,function(x) length(which(x[1:k] < x[k+1])))

3条回答
  •  孤城傲影
    2020-12-28 16:01

        >>> which = lambda lst:list(np.where(lst)[0])
    
        Example:
        >>> lst = map(lambda x:x<5, range(10))
        >>> lst
        [True, True, True, True, True, False, False, False, False, False]
        >>> which(lst)
        [0, 1, 2, 3, 4]
    

提交回复
热议问题