Finding the index of elements based on a condition using python list comprehension

前端 未结 5 2068
谎友^
谎友^ 2020-11-28 02:53

The following Python code appears to be very long winded when coming from a Matlab background

>>> a = [1, 2, 3, 1, 2, 3]
>>> [index for ind         


        
5条回答
  •  情话喂你
    2020-11-28 03:44

    For me it works well:

    >>> import numpy as np
    >>> a = np.array([1, 2, 3, 1, 2, 3])
    >>> np.where(a > 2)[0]
    [2 5]
    

提交回复
热议问题