Hope you are doing good. I want help in maxpooling using numpy. I am learning Python for data science, here I have to do maxpooling and average pooling for 2×2 matrix, the input can be 8×8 or more but I have to do maxpool for every 2×2 matrix. I have created an matrix by using ..
I’m running python code that’s similar to: import numpy def get_user_group(user, groups): if not user.group_id: user.group_id = assign(groups) return user.group_id def assign(groups): for group in groups: ids.append(group.id) percentages.append(group.percentage) # e.g. .33 assignment = numpy.random.choice(ids, p=percentages) return assignment We are running this in the wild against tens of thousands of users. I’ve noticed that the assignments ..
I want to write a code in python, which generates random numbers ranging from 1 to 1000, and if it generates 3 digit number ending precisely with *00 (two zeroes), the user wins. Here is my code example, which I am looking for to improve and make correct: trials = 10 win = 0 for ..
I am using numpy.random.seed to set a seed before a simulation by events loop. The seed works as expected as long I don’t change the file that calls and runs the simulation, but if change that file in any way the results of the simulation change (before or after the call from the function). I ..
I know this problem has been ask frequently but I just can’t solve it. I know that it’s not possible and this error occurs when you try to index the first value of a float. But in my case I’m indexing the first element of an array, at least I thought I did… Can anyone ..
I had some code that random-initialized some numpy arrays with: rng = np.random.default_rng(seed=seed) new_vectors = rng.uniform(-1.0, 1.0, target_shape).astype(np.float32) # [-1.0, 1.0) new_vectors /= vector_size And all was working well, all project tests passing. Unfortunately, uniform() returns np.float64, though downstream steps only want np.float32, and in some cases, this array is very large (think millions of ..
I’m developing a portfolio optimisation code with constraints using monte-carlo simulation. However, I have run into a problem. My problem is as follows: I have a list of instruments ["Multi", "Equity 1", "Equity 2", "Equity 3", "FI", "Cash"] And I would like to generate a list of random numbers for these instruments e.g. weights (random ..
This code is for a course assignment, which runs perfectly fine on Ubuntu 20.04 in Dell Inspiron laptop. However on macOS Catalina and Ubuntu 19.10 Virtual Box on MacBook Air the value of i printed is not deterministic as it should be. It varies from 2000 – 3500. While the i value printed in case ..