I am working on a segmentation problem where given an image, each RGB value corresponds to a class label. The problem I have is to efficiently map RGB values from an image (numpy array) to a corresponding class label image. Let’s provide the following simplified example: (in a real example the colorIdMap will have about 20 entries and labelOld will
Tag: numpy
Pandas rolling window to return an array
Here is a sample code. Output: I want my ‘C’ column to be an array like [0.1231, -1.132, 0.8766]. I tried using rolling apply but in vain. Expected Output: Answer You could use np.stride_tricks:
Equidistant points between two points?
I am trying to know equidistant points between two points. For example: The answer that I am expecting is: In this example, with p1, and p2: Always will be a straight line. HowManyParts in this case is the whole distance that is divided something like numpy.linspace() but in two dimensions. Answer Thanks to linearity of the line connecting two points,
Create an image using the pixels median fom other images
I have six images and I want to find the median of each pixel and create a new pic from it. I created a list of my images in this manner: and then I wrote a for loop like that: I’ve found that there’s a function that finds the median using numpy but I don’t know how to use it.
Apply log2 transformation to a pandas DataFrame
I want to apply log2 with applymap and np2.log2to a data and show it using boxplot, here is the code I have written: and below is the boxplot I get for my RAW data which is okay, but I do get the same boxplot after applying log2 transformation !!! can anyone please tell me what I am doing wrong and
NumPy/PyTorch extract subsets of images
In Numpy, given a stack of large images A of size(N,hl,wl), and coordinates x of size(N) and y of size(N) I want to get smaller images of size (N,16,16) In a for loop it would look like this: But can I do this just with indexing? Bonus question: Will this indexing also work in pytorch? If not how can I
Calculating monthly mean from daily netcdf file in python
Hello I have a netcdf file with daily data. Shape of the file is (5844, 89, 89) i.e 16 years data. I tried to get monthly average from daily data. I am looking for simillar to resample function in pandas dataframe. Is there anyways to do that in python. As I know it is very easy to calculate by using
Python pandas – new column’s value if the item is in the list
I want to create a new column in pandas dataframe. The first column contains names of countries. The list contains countries I am interested in (eg. in EU). The new colum should indicate if country from dataframe is in the list or not. Below is the shortened version of the code: The error I get is: ValueError: The truth value
Passing C++ vector to Numpy through Cython without copying and taking care of memory management automatically
Dealing with processing large matrices (NxM with 1K <= N <= 20K & 10K <= M <= 200K), I often need to pass Numpy matrices to C++ through Cython to get the job done and this works as expected & without copying. However, there are times when I need to initiate and preprocess a matrix in C++ and pass it
Expanding/Zooming in a numpy array
I have the following array: I want to expand it to this array: So I’m using the following command: based on this question and answer here Resampling a numpy array representing an image. However, what I’m getting is this: I want the expansion to be exactly by 3, or whatever the zoom factor is, but currently it’s different for each