All Questions
317 questions
-4
votes
1
answer
60
views
How to generate an array so that it does not change? [closed]
How to generate a list that will not change until I want it to?
random.sample(range(1, 15), 14)
every time the program is launched, a new list will be generated, how can I make it so that it does not ...
1
vote
1
answer
46
views
Iteration of a graph approximation
The code below runs a model based on a graph generated by the solution to a system of differential equations and shows one with random 5% error added to the points. How would I iterate this process (...
-1
votes
1
answer
91
views
How to roll 3 random strings out an array and check them
I am a student programmer at college and I've only recently started coding in my own time. I have some basic knowledge on how to program but arrays are out of my knowledge and I am trying to learn ...
1
vote
3
answers
117
views
Generating an array of random numbers with conditions
I have a list of length 64, such as first_list = [64, 27, 99, 133, 0, 41, ... ]. Numbers in this are some random selection from 0 to 150 (minimum value is 0 and maximum value is 149).
I want to ...
1
vote
2
answers
148
views
How to assign array values to the n-1 location in the array
I have an array like this: [1, 2, 3, 4, 5]. I shuffle it to get this: [1, 5, 4, 2, 3].
The Goal: Assign each value in the array to the n-1 location in the array
In other words, I need the number 1 to ...
0
votes
0
answers
13
views
Issues with randomly generating instance of object in 2d array [duplicate]
I have a 2d array and I want to randomly generate one of two objects in each spot arr[r][c]. However when I tried my code, instead of generating a random object at the spot, it generates the same ...
0
votes
0
answers
22
views
np.random.shuffle() is not working as expected [duplicate]
I want to shuffle the rows of my matrices. Here is my code:
#prepare the training data
dat_training = data_all_training[sbj]
labels_training = ...
0
votes
2
answers
101
views
How to split a list into exactly n randomly sized parts
I have to split a list of size >n (e.g.: lst = [1,2,3,4,5,6,7,8]) into exactly n randomly sized chunks (sublists), (e.g. chunks = [[1,2,3],[4],[5,6,7,8]]. The elements in the list are unique. The ...
2
votes
1
answer
46
views
How do i sample 6000 elements out of my 4-d array in numpy
So I'm working with an array named train_images of shape (25036, 12, 15, 15) , I need to select 6000 random samples from this array,
I've tried using np.random.choice()
It returned the error above, ...
2
votes
1
answer
2k
views
Generate random numbers in a range while keeping a minimum distance between values
I am after a function that produces an array with random numbers(between certain range), where no numerical value can be within a certain constant of another numerical value. This works best if it ...
1
vote
2
answers
207
views
Python: How to generate a random array only consisting of a specific number of -1, 0, 1?
Is there a standard way in Python to generate an array (of size 15), where precisely three 1s and four -1s are placed randomly and the remaining array entries are 0?
An example for such an array would ...
0
votes
3
answers
114
views
Trying to exclude an elements in an array if it overlaps with another array in Python
I am writing code that pseudorandomises positions from an array:
centre_pos = ['A','B','C','D','E']
corner_pos = ['1','2','3','4']
def position_generator():
#for centre, corner in zip(centre_pos, ...
0
votes
1
answer
65
views
Python list.index function with random probability on collision [duplicate]
Let's say I have a list: a = [1,1].
If I call a.index(1) it will always return 0.
Is there any pythonic way to return 0 or 1 in equal probabilities?
0
votes
1
answer
114
views
How to compare values in a list with a string?
I want to create a script which should prevent equal sentences. Firstly, I thought that it was enough to just check if the previous and the current sentence are the same. But it turned out that no ...
2
votes
2
answers
280
views
Randomly select argmax of non-unique maximum
Given a 2D numpy array, I want to construct an array out of the column indices of the maximum value of each row. So far, arr.argmax(1) works well. However, for my specific case, for some rows, 2 or ...