说我有序列s
,我想从中选择n
个随机子序列,每个子序列的长度为l
,并存储在矩阵中。是否有一种比
s = np.arange(0, 1000)
n = 5
l = 10
i = np.random.randint(0, len(s)-10, 5)
ss = np.array([s[x:x+l] for x in i])
答案 0 :(得分:1)
我们可以利用基于np.lib.stride_tricks.as_strided
的scikit-image's view_as_windows
进行有效的补丁提取,就像这样 -
{{1}}
相关:
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