I want to do linear regression to the data given by x and y. Everything seems to be fine when I use a linear plot, but when I want to plot it on a log scale the line does not look straight. I think I should divide the interval into finer grids rather than only six points. But I couldn’t
Tag: numpy
how do i remove rows from numpy array based on date?
i have a number of arrays with the following format: how do i remove the rows where the datetime > 2021-05-06 09:20 and < 2021-05-06 09:40 ? I have tried with np.delete: and np.where: but always get the error: SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers Edit in response to
Is there a way to speed up looping over numpy.where?
Imagine you have a segmentation map, where each object is identified by a unique index, e.g. looking similar to this: For each object, I would like to save which pixels it covers, but I could only come up with the standard for loop so far. Unfortunately, for larger images with thousands of individual objects, this turns out to be very
Find line number of a value which matches upto 2 decimal in python numpy
I tried to find the line number of value which is 60 % of the maximum value in file. My file looks like this, Now I print the line number of the max value by now how to find the line number which has 0.60 just comparing up to two decimal value only in python. Answer This will find the
How to concatenate the column by column name in pandas?
Is there any efficient way to concatenate Pandas column name, and don’t use loop. My current method is very slow. input : Output : Answer You could rework your dictionary to form groups and use groupby+agg(list): output:
Add features to the “numeric” dataset whose categorical value must be mapped using a conversion formula
I have this dataset: This is the request: “Add the Mjob and Fjob attributes to the “numeric” dataset whose categorical value must be mapped using a conversion formula of your choice.” Does anyone knows how to do it? For example: if ‘at_home’ value become ‘1’ in Mjob, I want the same result in the Fjob column. Same categorical values must
Most efficient way to check cells and change neighbors matching a condition in a dataframe
I’m using a pandas dataframe to store a dynamic 2D game map for a rougelike style game map editor. The player can draw and erase rooms. I need to draw walls around these changing rooms. I have this: And need this: What is the most efficient way to do this? So far I followed the approach outlined here, but this
How to implement a constrained linear fit in Python?
I’m trying to fit a linear model to a set of data, with the constraint that all the residuals (model – data) are positive – in other words, the model should be the “best overestimate”. Without this constraint, linear models can be easily found with numpy’s polyfit as shown below. example1 Is there an efficient way to implement a linear
calculate sum of squares with rows above
I have a dataset that looks like this: I want to iterate through each row and calculate a sum of squares value for each row above (only if the Type matches). I want to put this value in the X.sq column. So for example, in the first row, there’s nothing above. So only (-1.975767 x -1.975767). In the second row,
Return columns that are binary in ndarray?
So for the same thing does for a panda dataframe. I want to know how to do this when it is a ndarray? 1 40 0 0 0 0 0 0 2 58 0 0 1 0 0 0 3 41 0 1 1 0 0 1 4 45 0 0 1 1 0 1 5 60 0 1 0