首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用坐标随机采样网格

使用坐标随机采样网格
EN

Stack Overflow用户
提问于 2017-01-13 02:42:42
回答 1查看 369关注 0票数 0

我在一张图片上放置了一个编号网格(19 X 22),我需要从418帧中随机选择250帧。有没有一种方法可以通过随机选择x和y坐标来实现这一点,而不需要任何重复的坐标?

谢谢

Example of grid over image (rows and columns are not labeled)

EN

回答 1

Stack Overflow用户

发布于 2017-01-13 03:09:05

这里有一个快速而肮脏的方法,可以生成随机的X和Y值,而不需要在网格中重复。

代码语言:javascript
复制
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)

如果您发布一个您想要采样的数据类型的代码示例,我也许能够简化。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41620639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档