Say I have a multi-dimensional array, for example: And say I have a one-dimensional array (b), with some values which may be seen in my multi-dimensional array (a): Now I want to replace all of the non-intersecting values in array a with zero. I want to get the following result: How could I achieve this? I tried several ways of
Tag: arrays
How to turn a pandas DataFrame of lists of numbers into a 3-dimensional array?
I have a pandas DataFrame with a structure like this: (to build it, do something like What would be the simplest way to turn it into a NumPy 3-dimensional array? This would be the expected result: I have tried several things, without success: Answer One option is to convert df to a list; then cast to numpy array: Output:
Exctract a value from a Json file(python)
Hi i’m not an expert and this problem kept me stuck for such a long time I hope that someone here can help me i would like to exctract the value “interestExpense” from the following json file: In this case the result should be -130000000 as a string but i m trying to find a way to create an list(or
How to make list numbers by formula
hey everyone i have a question how i make a formula that makes my numbers in list specific first i need it to start whith number 4 then if if its higher than 6 it needs to restart from 0 it would look like this 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4
How to make a boolean array by checking if the items in an array is in a list?
I’m trying to find every item in an numpy array arr that’s also in an arbitrary list lst and replace them, but while arr > 0 will generate a boolean array for easy masking, arr in lst only works with all() or any() which isn’t what I need. Example input: array (1, 2, 3, 4, 5), list [2, 4, 6,
How to create a numpy 2-D array whose elements depend on elements of two lists already fixed
Example: Let and I would like to create a matrix C of size (5,5) whose elements are where f is a fixed function for example f(x,y) = x*y + x + y which means In the case where c_ij depends on i and j only and does not depend on the lists A and B, we can use np.fromfunction(lambda i,j:
Slicing a 3D image to create a 2D image
I have several 3D images of shape (32,32,32) and I want to create 2D images from them. I want to do that by getting each slice in the z-axis and putting each of them in a square array in order, something like this: Because I want the 2D image to be square I need to fill the missing slices with
Python count amount of cells forming a line with random shape in an array
Context: I work with satellite images that I filter to transform to arrays of 1s and 0s, based on the presence of snow (0 for snow, 1 for non-snow). My code creates an array of NaNs, searches for each snow pixel if at least one of the neighbor is non-snow (in a cross patter, cells painted red in the picture
Finding location of subarray in numpy array
I want to find the location of a subarray in an numpy array. For example, if the large array is of shape (10000, 10, 10, 10), namely 10000 arrays of shape (10,10,10) and I want to find the location of the subarray of shape (3,3,3) as follows: So I will know that at the location of n, i, j, k
How to loop through lists to create multiple plots Python
I have the following three lists: I was wondering how I can take these 3 lists and iterate through them to get lists so the first plot would be plotting dog as title with y value as the first list in 2d list 2 and the x value would the first list in 2d list 3. This would iterate for