All Questions
Tagged with probability arrays
79
questions
14
votes
5
answers
3k
views
Choose random array element satisfying certain property
Suppose I have a list, called elements, each of which does or does not satisfy some boolean property p. I want to choose one of the elements that satisfies p by random with uniform distribution. I ...
11
votes
1
answer
52k
views
Distribution plot of an array
I have a numpy array containing float values in [-10..10]. I would like to plot a distribution-graph of the values, like this (here it is done for a binomial random variable) :
For example I would ...
8
votes
3
answers
6k
views
Returning a random value from array with probability proportional to it's value
I have an array like
$keywords = array('apple'=>10,'orange'=>2,'grape'=>12);
I want to randomly pick one of the "Key" from the array. However the probability distribution should be such ...
8
votes
1
answer
122
views
Function that returns array of array combinations
I'm trying to make a _.combinations function (underscore mixin) that takes three parameters arr, pockets, duplicates. Here's a test that I designed to show how the behavior should be.
expect(_....
6
votes
2
answers
3k
views
Get random item for array based on different probabilities?
Okay, imagine I'm creating a Pokemon game in JavaScript. I have an object like this...
pokemon = {
"pikachu": {hp: 100, probability: 0.1},
"squirtle": {hp: 90, probability: 0.2}
};
I basically ...
5
votes
3
answers
4k
views
Generating random numbers with weighted probabilities in python
Given a positive integer array a, the goal is to generate 5 random numbers based on the weight they have in the array.
For example:
a = [2,3,4,4,4,4,4,6,7,8,9]
In this case the number 4 has ...
5
votes
1
answer
6k
views
Best way to get joint probability from 2D numpy
Was wondering if there is a better way to get the probability of a 2D numpy array. Maybe using some of numpy's built in functions.
For simplicity, say we have an example array:
[['apple','pie'],
['...
4
votes
1
answer
1k
views
Can you return n choose k combinations in Javascript using Array.flatMap?
For instance, this is 5 choose 2:
var array = [0,1,2,3,4];
var result = array.flatMap(
(v, i) => array.slice(i+1).map(w => [v, w])
);
console.log(result);
...
4
votes
5
answers
765
views
PHP: How to select maximum probability value randomly?
I have below array & code
$a = [
149 => 55,
130 => 10,
131 => 5,
132 => 5,
133 => 10,
134 => 10,
135 => 5
];
$rand = ...
4
votes
4
answers
1k
views
How to return index of an element with probability of the element's value divided by sum of array
Given an array and a value k, write a function to return index of element that equals to k with the probability of k/sum(input array). Assume there is no duplicate number in input array.
For example,...
4
votes
1
answer
847
views
Randomize matrix elements between two values while keeping row and column sums fixed (MATLAB)
I have a bit of a technical issue, but I feel like it should be possible with MATLAB's powerful toolset.
What I have is a random n by n matrix of 0's and w's, say generated with
A=w*(rand(n,n)<p)...
3
votes
1
answer
839
views
How to create function of tossing coin R
I'm trying to create a function in R to simulate the experiment of tossing four coins as many times as m times, each experiment records the appearance of "numbers" or "images" on each coin.
Present ...
3
votes
2
answers
65
views
Certainty of data distribution profile when performing a sort operation
Lets assume we have some data structure like an array of n entries, and for arguments sake lets assume that the data has bounded numerical values .
Is there a way to determine the profile of the ...
2
votes
2
answers
170
views
Find item in array using weighed probability and a value
Last week I had some problems with a simple program I am doing and somebody here helped me. Now I have run into another problem.
I currently have this code:
var findItem = function(desiredItem) {
...
2
votes
2
answers
776
views
Using an array of percentages to determine probability?
After trying a challenge in java to make a 'casino' style game, I've arrived at the point where I have an array with 10 values, each being the percentage change they can win. These are assigned to the ...
2
votes
1
answer
1k
views
Sort array using probability distributon
An array shall be sorted high to low by its values.
<?php
$items = array(
1 => f(1),
2 => f(2),
3 => f(3),
4 => f(4),
5 => f(5),
);
?>
After sorting I look which item ...
2
votes
2
answers
344
views
Ensure that contents of list sums up to 1 for np.random.choice()
The Context
In Python 3.5, I'm making a function to generate a map with different biomes - a 2-dimensional list with the first layer representing the lines of the Y-axis and the items representing ...
2
votes
2
answers
185
views
Empirical distribution of rows in 2d numpy array
Let's say I have a 2d numpy array A:
A = [[0.3, 0.2],
[1.0, 0.1],
[0.3, 0.1],
[1.0, 0.1]]
What I would like is something that maps rows of A to their empirical distribution:
f([0.3, ...
2
votes
2
answers
2k
views
Probability that two items are compared
I'm attempting to solve the following problem (from Prof. Jeff Erikson's notes):
Given the algorithm below which takes in an unsorted array A and returns the k-th smallest element in the array (given ...
1
vote
2
answers
57
views
Julia, conditionally substitution of individual elements
I asked a question about this earlier but may be over-complicating the issue. Given an array:
a = [3,4,3,6,3];
what code do I need to execute the following:
if the individual element of a == 3
then ...
1
vote
2
answers
141
views
Python noob: manipulating arrays
I have already asked a few questions on here about this same topic, but I'm really trying not to disappoint the professor I'm doing research with. This is my first time using Python and I may have ...
1
vote
2
answers
82
views
Probability of 1 to n number combination
I want the combination of the number 1 to nth.
Example sets:
Number Range: 1,2,3
Combination of output in 2 digits ( if number range is 1 to 4 then I want it in 2 or 4 digit. So it's dynamic base ...
1
vote
2
answers
73
views
Using a number array to adjust the chances of a specific return value?
I am creating a method called getRandomLetter() that I want to randomly return a single letter from the English alphabet. I want the method to be more likely to return a letter with a higher number ...
1
vote
1
answer
290
views
Python: find consecutive values in 3D numpy array without using groupby?
Say that you have the following 3D numpy array:
matrices=
numpy.array([[[1, 0, 0], #Level 0
[1, 1, 1],
[0, 1, 1]],
[[0, 1, 0], #Level 1
[1, 1, ...
1
vote
1
answer
792
views
How do I fill an array according to distributions for each element in Python?
Suppose I have 3 boxes and 3 animals and I want to create an array of boxes containing 1 animal each according to their respective distributions:
animals = ["Cat", "Dog", "...
1
vote
1
answer
20k
views
How to change the z value to the one from the table (Z-Table from Normal Distribution) in C++?
i have task to make a program using C++ to calculate a probability using a normal distribution. If i already found the Z value, how to change it to become the one from the Z table? Like -0.55, in the ...
1
vote
1
answer
958
views
Probability of generating a set of M elements from an array of size N [duplicate]
I'm trying to understand solution for the following task:
Randomly generate a set of M elements from an array of size N. Each element must have equal probability of being chosen.
I found the ...
1
vote
3
answers
2k
views
Generate a set of M elements from an array of size N
UPDATE: according to the comments let's make some clarifications.
I'm trying to understand solution for the following task:
Randomly generate a set of M elements from an array of size N. Each element ...
1
vote
1
answer
161
views
Get content from arrays with declared probability in JS
i want to draw values from two or more arrays. For example arrays 'age' which contain values 1-99 and second array 'earnings' which contain 2000-10000.
If i will draw 'age' more than 30 i would like ...
1
vote
1
answer
2k
views
Calculating conditional probabilities from joint pmfs in numpy, too slow. Ideas? (python-numpy)
I have a conjunctive probability mass function array, with shape, for example (1,2,3,4,5,6) and I want to calculate the probability table, conditional to a value for some of the dimensions (export the ...
1
vote
1
answer
86
views
Trying to run a test to see how many children it takes to have one of each sex but the array is not working properly?
I am running some code for a class and I have no clue what to do, I submitted the assignment but it's not helpful if I don't know what to do in the end. Here is the code that I am running to try and ...
1
vote
1
answer
84
views
Probabilistic Random Selection from Dynamic Array
I'm new to VBA here. I have 2 lists, a list of price, and a list of the probabilities assigned to the price. I need to generate a list of 300 numbers based on the probability group. However, I can't ...
1
vote
2
answers
3k
views
Dice Roll Simulator C++
In class we received an assignment to make a C++ program that simulates rolling a die (or multiple). Simple enough, I did that really easy, even got it to roll more than 1 die at once and to count how ...
1
vote
1
answer
194
views
Extract number with given probabilities in C [duplicate]
Let's say I have an array probabilities = [0.1, 0.2, ..., 0.1, 0.4] of n elements. These are floating point values, not integer weights.
How do I extract a random integer from 1 to n with the given ...
0
votes
4
answers
498
views
Average distance between two randomly chosen indexes in array [closed]
Interesting thought question for you guys. Given an array of length n, if I were to pick two random indexes in this array, a and b on average how far apart would they be? As in how many steps would I ...
0
votes
1
answer
54
views
Calculating the probability of incorrect events within independent groups
I have the following structure:
T = struct('Time',{20, 40, 50, 80, 120, 150, 190, 210, 250, 260, 270, 320, 350, 380, 385, 390, 395},...
'Trial',{'correct','incorrect','incorrect','correct'...
0
votes
1
answer
2k
views
Dice Statistics Program
I'm trying to write a java program that asks the user to enter in the amount of dice to roll and the amount of times to roll the dice.
The program that I wrote so far isn't rolling the dice properly: ...
0
votes
2
answers
2k
views
Calculating probability with given ranges
In a couple of last application I was supposed to implement Probability which was usually given among some items say:
reward a user on certain level completion item X
item X may be one of the below:
...
0
votes
1
answer
145
views
Change in precision value of numpy float32 while summing up the elements [duplicate]
I have an array and I would like to calculate the sum of the elements column wise (column_sum) and divide the column elements with the column_sum, so that after division, the sum of column elements ...
0
votes
4
answers
188
views
How to sample without replacement using only the number of elements of each class?
I have a list of strings (["A", "B", ...]) and a list of sizes ([4,7,...]). I would like to sample without replacement from the set of strings where initially string in position i ...
0
votes
2
answers
614
views
Generate list of numbers from a list with probability weights [closed]
How would one go about generating a list of random numbers from a list of 35 numbers with given probabilities:
Probability of number in range (1,5) - p1 = 0.5
Probability of number in range (6,15) - ...
0
votes
2
answers
62
views
Mutate an array of discrete probabilities by excluding one value in C
I am working in a project in C where I want to progressively mutate a uint32_t under the following conditions:
The probability of a bit flip starts out with probability 1/2 for the least significant ...
0
votes
1
answer
37
views
Julia, perform substitution with on a probability basis
I'm working with an array from a 3d array, and with lots of previous help here, got a very nice simple elegant solution :
## Reset 44 and 33 to 4 and 3 respectively
replace!(@view(Pop[end, :, 1]), 33=&...
0
votes
1
answer
217
views
How to manage probabilities in an array?
I have 2 2D arrays that store data for a fractal. My first array has 3 rows and the last value of each row is the probability.
Row 1 has 0.33 probability,
Row 2 has 0.33 probability, and
Row 3 has 0....
0
votes
1
answer
972
views
How to ensure that the contents of the list will always sum up to 1? [closed]
I am trying to have a probability list, which I have to renew all the time when a new element joins. My code is:
sum=7
my_list = [2,2,2,1]
prob_list = list(map(lambda x: float(x/sum), my_list))
...
0
votes
3
answers
627
views
Adding random values from array with some probability
Let's say I have a code for a windows form, that generates greetings when you press a button.
string[] Greetings = new string[] { "Hi", "Hello", "Howdy!", "Hey" };
string[] Smilies = new string[...
0
votes
4
answers
1k
views
'Normalizing' Probability Array
I have an array of doubles representing probabilities of certain events happening, [25,25,25,10,15] for event A,B..E. The numbers add up to 100.
Through my analysis I want to be able to cross off the ...
0
votes
1
answer
33
views
How do you construct an array with elements that follow a distribution and sum to 1?
I was trying to make a program that produces a list that functions as a probability distribution for another list based on a probability falloff. To do this, I found that the core of the issue lay in ...
0
votes
1
answer
165
views
In swift, how to generate a multidimensional array? [closed]
I have an array :
let myArray : [Int] = [1, 1, 1]
3 numbers are an example. In the reality, it will be different each time.
And I have variables of minimum and maximum
let valueMin = 1
let valueMax = ...
0
votes
3
answers
249
views
How to get random index of the array without current idx?
I'm iterating over a list (numpy array with one dimension to be exact) and I need to pick an index form this list that is random and different than current iterator.
The most important thing is ...