All, I’m new to python, so hopefully this is not a dumb question, but I have not been able to find out directions/information of how to do this task. I am trying to create a program that determines if a given pixel is within a certain region. The method I found that recommended how to test this involves calculating polygonal

# Tag: numpy

## Why is this array changing when I’m not operating on it?

I have two arrays: And I’m running the foll)owing code: I get the following result: Why are the last elements changed? I don’t see why X is changed by indexing some elements. edit: added np.array Answer Output:

## 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

## 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

## Creating 3d Tensor Array from 2d Array (Python)

I have two numpy arrays (4×4 each). I would like to concatenate them to a tensor of (4x4x2) in which the first ‘sheet’ is the first array, second ‘sheet’ is the second array, etc. However, when I try np.stack the output of d[1] is not showing the correct values of the first matrix. Answer If you do np.dstack((x, y)), which

## How do you slice a cross section in pandas or numpy?

I have the following data frame which can be copy/pasted and made to a data frame with: df = pd.read_clipboard() I would like to take a cross section from it, I want something like say: [1, 4, 9, 1, 10, 6, 4, 0, 4, 6, 10, 1, 9, 4, 1]) which is index df.loc[1, 0], df.loc[2, 1], df.loc[3, 2], df.loc[4,

## how to split a numpy array into subarrays based on values of one colums

I have a big numpy array and want to split it. I have read this solution but it could not help me. The target column can have several values but I know based on which one I want to split it. In my simplified example the target column is the third one and I want to split it based on

## Simple Linear Regression not converging

In my attempt to dig deeper in the math behind machine learning models, I’m implementing a Ordinary Least Square algorithm in Python, using vectorization. My references are: https://github.com/paulaceccon/courses/blob/main/machine_learning_specialization/supervisioned_regression/2_multiple_regression.pdf https://www.geeksforgeeks.org/linear-regression-implementation-from-scratch-using-python/ This is what I have now: The problem I’m facing is that my weights keep increasing until I end up getting a bunch of nans. I’ve been trying to find out

## How can I select top k rows based on another dataframe in python?

I have data as follows. Users are 1001 to 1004 (but actual data has one million users). Each user has corresponding probabilities for the variables AT1 to AT6. I would like to select the top 3 users for each choice based on the following data. In the output, top1 to top3 are the top 3 users based on probability for

## Change x-axis scale size in a bar graph

For some set of data, here is my code which generates a bar graph like this: The values on the x-axis ranges from 1975 to 2017. And the values on the y-axis are some decimal values. In the x-axis of the plot, the values are overlapping. I want to change the scale as 1975, 1980, 1985 so on to keep