Linked Questions

4 votes
4 answers
9k views

I want to randomly produce an array of n ones and m zeros. I thought of this solution: produce the ones array (np.ones) produce the zeros array (np.zeros) combine them to one array (np.hstack) ...
Tengis's user avatar
  • 2,839
3 votes
0 answers
60 views

I have come with the following code to generate an array of size: arr_size, containing only 1's and 0's so that, on average, it'll have "threshold" 1's in it. Here's the code: import numpy as np ...
Eran Moshe's user avatar
  • 3,238
30 votes
5 answers
52k views

I want to generate a random array of size N which only contains 0 and 1, I want my array to have some ratio between 0 and 1. For example, 90% of the array be 1 and the remaining 10% be 0 (I want this ...
Am1rr3zA's user avatar
  • 7,461
5 votes
3 answers
1k views

I need to create a 3D tensor like this (5,3,2) for example array([[[0, 0], [0, 1], [0, 0]], [[1, 0], [0, 0], [0, 0]], [[0, 0], [1, 0], [...
Atul Vinayak's user avatar
2 votes
1 answer
1k views

Before I explain, here is my code for reference: import numpy as np arrayteam = [[3,3,3,3,3,3],[2,2,2,2,2,2],[1,1,1,1,1,1]] #nteams = 3 #nsubteam = 2 #newnums = np.zeros((len(arrayteam),len(...
Noriana 's user avatar
-4 votes
1 answer
3k views

I am doing a task to simulate Schelling's Model of Segregation. Now I would like to know the following: 1)how do I generate a 2d matrix(grid) with 100x100cells using numpy 2) how to fill the matrix ...
Desibre93's user avatar
0 votes
1 answer
2k views

I am new to programming and hoping somebody can help me with a specific problem I have. I want to form clusters in a 100x100 binary numpy ndarray under two conditions: I want to specify the number ...
VisaVis's user avatar
  • 11
1 vote
1 answer
519 views

I was trying to write a function that gets a matrix of 2D points and a probability p and change or swap each points coordinates with probability p So I asked a question and I was trying to use a ...
Cupitor's user avatar
  • 11.8k
-1 votes
2 answers
272 views

I'd like to generate an int random number between 0 and 1 n number of times. I know the code to generate this: num_samp = np.random.randint(0, 2, size= 20) However, I need to specify a condition that ...
Babz's user avatar
  • 15
0 votes
3 answers
106 views

I would like to create a function that takes three arguments (n,m,d) and it should output a matrix with n rows and m columns. The matrix should be populated with values 0 and 1 at random, in order to ...
João Garcia's user avatar