python – 如何从numpy数组中提取多个随机子序列

python – 如何从numpy数组中提取多个随机子序列,第1张

概述说我有一个序列s,我想从中选择n个随机子序列,每个子序列的长度为l,并存储在矩阵中.有没有更多的方式来做到这一点 s = np.arange(0, 1000)n = 5l = 10i = np.random.randint(0, len(s)-10, 5)ss = np.array([s[x:x+l] for x in i]) 我们可以利用基于 np.lib.stride_tricks.a 说我有一个序列s,我想从中选择n个随机子序列,每个子序列的长度为l,并存储在矩阵中.有没有更多的方式来做到这一点

s = np.arange(0,1000)n = 5l = 10i = np.random.randint(0,len(s)-10,5)ss = np.array([s[x:x+l] for x in i])
解决方法 我们可以利用基于 np.lib.stride_tricks.as_stridedscikit-image's view_as_windows进行高效的补丁提取,就像这样 –

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 outputout = w[i]

相关:

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

总结

以上是内存溢出为你收集整理的python – 如何从numpy数组中提取多个随机子序列全部内容,希望文章能够帮你解决python – 如何从numpy数组中提取多个随机子序列所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1191031.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-03
下一篇2022-06-03

发表评论

登录后才能评论

评论列表(0条)

    保存