I’m currently trying to run a MonteCarlo simulation without replacement, using np.random.choice, but there are certain items in the list which cannot appear together. For example, if I have a list of five items: RO, MI, VE,NA, SI, and each loop produces a group of four items, RO can appear with VE, MI, or NA, but it cannot appear with
Tag: numpy
Adding multiple constant values in a pandas dataframe column
I would like to know how to add multiple constant values of different lengths into a dataframe column. I know that we can add a single constant value (for example: 5) to a data frame column ‘A’ like this: But I want to have the dataframe something like the table below. As you can see, I need three 5s, two
How to get the coefficients of the polynomial in python
I need to create a function get_polynom that will take a list of tuples (x1, y1), (x2, y2), …, (xn, yn) representing points and find the coefficients of the polynomial c0, c1, …, cn. I can’t manage to understand the task, the only tip I have is the provided part of the function: Have somebody done something similar? Just a
Excel column manipulation
I am trying to find cell named North and take everything below it I know that we can easily locate this using loc and iloc, but in my case it may vary every time my app opens new excel file. I tried using str.contains Answer Try with iloc and idxmax:
How to apply function vertically in df
I want to add column values vertically from top to down I tried using apply but its not working Desired output is basically adding A column values 1+2, 2+3: Answer You can apply rolling.sum on a moving window of size 2:
summing the values row wise
I have a three column of data as arranged below: Input file: In the above input file the first column values are repeated so I want to take only once that value and want to sum the third column values row wise and do not want to take any second column values. I also want to append a third column
Modules at VS code notebook [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question
FAST: 1D overlaps with rows in 2D?
let say i have 2D array, f.e.: I want to calculate overlap with 1D vector, FAST. I can almost do it with (8ms on big array): The problem with it is that it only matches if both Position and Value match. F.e. 5 in 2nd column of 1d vec did not match with 5 in 3rd column on the 2nd
Filter based on pairs within a group – if value represent at BOTH ends
Within each group there are pairs. In Group 1 for example; the pairs are (2,2),(2,4),(4,1) I want to filter these pairs based on code numbers 2 AND 4 being present at BOTH ends(not either) In group 1 for example, only (2,4) will be kept while (2,2) and (4,1) will be filtered out. Excepted Output: Answer You can approach by making
Manipulating numpy arrays (concatenating inner sub-arrays)
I have a question of manipulating numpy arrays. Say, given a 3-d array in the form np.array([[[1,2],[3,4]], [[5,6],[7,8]]]) which is a (2,2,2) array. I want to manipulate it into a (2,4) array such that a = np.array([[1,2,5,6],[3,4,7,8]]). I want to know is there any built-in methods of numpy particularly dealing with problems like this and can be easily generalized. EDITED: