Consider a data frame with 97 rows and 44 columns where i have three columns whose names are “Bostwick”,”mu_yield” , so i’m trying to create a new column called “Target” where if the “Bostwick” column values lie between “5.00 and 6.75” else if “mu_yield” column values lie between “89.00 and 90.00” , the “Target” column values should be 0 else
Tag: numpy
How to add elements of a 1D NumPy array to NumPy subarrays with the same index?
Let’s say I have a NumPy array a with shape (3, 5, 7) and a 1D NumPy array l with shape (3, 1). I want to add the 0th element of l to the 0th subarray in a, the 1st element of l to the 1st subarray of a, and the 2nd element of l to the 2nd and last
How could I generate a 2D array from a known slope and aspect value?
Given a dummy heightmap (or digital elevation model) stored as a Numpy array like this: I can calculate its slope and aspect like this: And visualise it: But how would I go the other way? I’d like to generate a blank 2D Numpy array of a fixed size, then fill it with values that follow a known slope and aspect
Fastest way to find a 2d array inside another array that holds multiple 2d arrays
Hi I’m trying to perform a search operation in an array that contains multiple 2d arrays comparing it’s itens to a specific array. I managed to do it using a for loop iterating trough the itens inside the big array but I have to perform this search 10^6 times and the length of this for loop can grow up to
Changing specific elements in a list of list of numpy arrays
I have a list of lists of numpy arrays. I would like to loop through the list of lists and change certain elements. Below is an example, but just with integers: The i==j element has been changed to something else. When I run the exact same code logic, but with 2×2 numpy arrays, I cannot get it to do the
Which library/function should I use to fit a multivariate polynom to my data?
I have data that depends on 4 independent variables (x1,x2,x3,x4) and I need a model (available in Python) to evaluate f(x1,x2,x3,x4) outside the data points. In principle, if I set 3 of my variables as constant values I can always use a polynomial fit of a reasonable degree (<5) to interpolate the data in the remaining dimension so I would
Solve linear system in python with different set of roots
I’m having a problem where I have this linear system for example I need to solve for x1, x2, and x3 but every library I used gave me only x1=x2=x3=0 as a solution it’s correct but the system accepts other solution. I am looking for a solution to avoid zeros as answer. Thanks for helping. Answer That’s more of a
How to broadcast from 3-dimensional matrix using indices from 2-D matrix?
I have a specific matrix with dimensions (nz,ny,nx) and another matrix with dimensions (ny,nx). In this other matrix are specific values and for instance I want to sum all the points in this first 3-dimensional matrix at locations where the second matrix has a specific value. I am doing the following: which has (2,X) elements and when I now try
I am getting ValueError: invalid literal for int() with base 10 with np.where function
I want to change ‘not available’ value in a df column into 0, and for the rest of the values to change them into integers. Unique values in the column are: I run the following code to change values to integers: I expect that the above would turn all values into integers, yet I get the value error Any suggestion
Part specification along different axes of numpy array
Why is arr[0:5][0:10] the same as arr[0:10][0:5] and what should I write if I want to get the array with shape (10,5)? In the process of trying to crop a 2D numpy array I end up with the wrong dimensions. Ok, I figure, I just got my axes switched up, so I switch the order of the part specification.. and