sample

Pick one random element from a vector for each row of a data.table

旧街凉风 提交于 2019-12-02 01:29:29
I have a dataframe of names. And I have a vector of different food items. I want to pick one element from that vector randomly for each Name so that the data.table looks like below. x<- c("apple","pepsi","rice","coke","banana","butter","bread") library(data.table) dt <- fread(' Name NextItem John rice Logan butter Sarah bread Vinny rice ') I want the sampling with replacement. I have tried dt[,NextItem:= sample(x,1)] but it samples the same food item(vector element) for everyone, not different random elements like aforementioned example. We can use group by option and then do sample dt[,

How to return sample row from database one by one

别等时光非礼了梦想. 提交于 2019-12-01 14:03:17
Web page should show one product image for specific product category from PostgreSql database. This image should changed automatically to other image after every 25 seconds. Returned product may be random or in some sequence. Some product may be missing and some repeated but most of the products in criteria should returned. Total available image count may change slightly between sample retrieval Currently code below is used which is executed after every 25 seconds. This requires two queries to database: one for count which may be slwo and second for single image retrieval. In both cases where

OpenCV createsamples - invalid background description file

…衆ロ難τιáo~ 提交于 2019-12-01 12:01:40
I'm in my OPENCV_ROOT folder and running the following command in Win-x64: opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg -bg ABSOLUTE_PATH_TO_PROJECT\negatives.txt -vec ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec -num 125 My negatives.txt looks like this: negative_images\city01_02.jpg negative_images\city01_04.jpg negative_images\city01_05.jpg negative_images\city01_06.jpg negative_images\city01_07.jpg This is my output: Info file name: (NULL) Img file name: ABSOLUTE_PATH_TO

OpenCV createsamples - invalid background description file

被刻印的时光 ゝ 提交于 2019-12-01 11:58:53
问题 I'm in my OPENCV_ROOT folder and running the following command in Win-x64: opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg -bg ABSOLUTE_PATH_TO_PROJECT\negatives.txt -vec ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec -num 125 My negatives.txt looks like this: negative_images\city01_02.jpg negative_images\city01_04.jpg negative_images\city01_05.jpg negative_images\city01_06.jpg

Deploying the Ballerina integration example in a Docker container

风流意气都作罢 提交于 2019-12-01 09:20:32
On the Ballerina Quick Tour page, there is an example on deploying a previously created integration microservice (which is supposed to send a Tweet) within in a docker container. However, that part of the documentation doesn't describe how to package the "twitter.toml" (authentication details) within the container. Therefore, it doesn't work as it does when it wasn't deployed within a container. How can this be resolved? The piece on copying the config file is missing there. Try adding the @docker:CopyFiles annotation as well. The following worked for me: @docker:Config { registry:"registry

Python random sample generator (comfortable with huge population sizes)

∥☆過路亽.° 提交于 2019-12-01 09:20:32
As you might know random.sample(population,sample_size) quickly returns a random sample, but what if you don't know in advance the size of the sample? You end up in sampling the entire population, or shuffling it, which is the same. But this can be wasteful (if the majority of sample sizes come up to be small compared to population size) or even unfeasible (if population size is huge, running out of memory). Also, what if your code needs to jump from here to there before picking the next element of the sample? P.S. I bumped into the need of optimizing random sample while working on simulated

Generating random numbers (0 and 1) given specific probability values in R

梦想的初衷 提交于 2019-12-01 07:17:05
问题 I could not find answer for this question in R. I would like to generate a random sample of 0 to 1's 'RandomSample'. For each sample I would like to have a specific number of values 'numval' which is derived from the length of the vector 'Prob'. 'Prob' is giving me probability value that each individual point will be 0 or 1. So in this instance first number will have prob value of 0.9 being 1, and 0.1 being 0. And so on. Then, I would like to repeat random sample generation 1000 times. I have

Python random sample generator (comfortable with huge population sizes)

回眸只為那壹抹淺笑 提交于 2019-12-01 07:10:45
问题 As you might know random.sample(population,sample_size) quickly returns a random sample, but what if you don't know in advance the size of the sample? You end up in sampling the entire population, or shuffling it, which is the same. But this can be wasteful (if the majority of sample sizes come up to be small compared to population size) or even unfeasible (if population size is huge, running out of memory). Also, what if your code needs to jump from here to there before picking the next

Deploying the Ballerina integration example in a Docker container

做~自己de王妃 提交于 2019-12-01 07:07:56
问题 On the Ballerina Quick Tour page, there is an example on deploying a previously created integration microservice (which is supposed to send a Tweet) within in a docker container. However, that part of the documentation doesn't describe how to package the "twitter.toml" (authentication details) within the container. Therefore, it doesn't work as it does when it wasn't deployed within a container. How can this be resolved? 回答1: The piece on copying the config file is missing there. Try adding

Ignoring values or NAs in the sample function

梦想与她 提交于 2019-12-01 04:34:16
问题 I have a matrix in R that I would like to take a single random sample from each row. Some of my data is in NA, but when taking the random sample I do not want the NA to be an option for the sampling. How would I accomplish this? For example, a <- matrix (c(rep(5, 10), rep(10, 10), rep(NA, 5)), ncol=5, nrow=5) a [,1] [,2] [,3] [,4] [,5] [1,] 5 5 10 10 NA [2,] 5 5 10 10 NA [3,] 5 5 10 10 NA [4,] 5 5 10 10 NA [5,] 5 5 10 10 NA When I apply the sample function to this matrix to output another