how can I extract multiple random sub-sequences from a numpy array

前端 未结 1 1765
无人共我
无人共我 2020-12-04 02:57

say I have a sequence s and I\'d like to select n random sub sequences from it each with length l and store in a matrix. Is there a mo

相关标签:
1条回答
  • 2020-12-04 03:41

    We can leverage np.lib.stride_tricks.as_strided based scikit-image's view_as_windows for efficient patch extraction, like so -

    from skimage.util.shape import view_as_windows
    
    # Get sliding windows (these are simply views)
    w = view_as_windows(s, l)
    
    # Index with indices, i for desired output
    out = w[i]
    

    Related :

    NumPy Fancy Indexing - Crop different ROIs from different channels

    Take N first values from every row in NumPy matrix that fulfill condition

    Selecting Random Windows from Multidimensional Numpy Array Rows

    0 讨论(0)
提交回复
热议问题