我在一张图片上放置了一个编号网格(19 X 22),我需要从418帧中随机选择250帧。有没有一种方法可以通过随机选择x和y坐标来实现这一点,而不需要任何重复的坐标?
谢谢
Example of grid over image (rows and columns are not labeled)
发布于 2017-01-13 03:09:05
这里有一个快速而肮脏的方法,可以生成随机的X和Y值,而不需要在网格中重复。
library(tidyverse) # Gives us both %>% and filter_n
# Create a dataframe (technically a tibble) with one cell for each
# cell in your grid
combos <- expand.grid(x = seq(1, 19, 1), y = seq(1, 22, 1)) %>%
tbl_df()
# Draw 250 random samples from the data without replacement
# If you post more information about the data you're using,
# I might be able to skip the creation of the combos data entirely
grid_sample <- sample_n(combos, size = 250, replace = FALSE)如果您发布一个您想要采样的数据类型的代码示例,我也许能够简化。
https://stackoverflow.com/questions/41620639
复制相似问题