Skip to content
Advertisement

Tag: numpy

Replace cv2.warpPerspective for big images

I use python OpenCV to register images, and once I’ve found the homography matrix H, I use cv2.warpPerspective to compute final the transformation. However, it seems that cv2.warpPerspective is limited to short encoding for performance purposes, see here. I didn’t some test, and indeed the limit of image dimension is 32767 pixels so 2^15, which makes sense with the explanation

merge columns in numpy matrix

I have a NumPy matrix like this one (it could have several columns, this is just an example: I need to merge all columns in this matrix, replacing nan values with the corresponding non-nan value (if exists). Example output: Is there a way to achieve this with some built-in function in NumPy? EDIT: if there is more than one non-nan

How to efficiently do operation on pandas each group

So I have a data frame like this– What I am doing is grouping by id and doing rolling operation on the delay column like below– It is working just fine but I am curious whether .apply on grouped data frame is vectorized or not. Since my dataset is huge, is there a better-vectorized way to do this kind of

How to change pixel value based on a condition

The image is 1920 by 1080. How can I change the value of a pixel when a channel value is higher than the other? Here is what I did. Is there a more efficient way than iterating on each pixel? Answer Don’t use any loop for this, use ndarray capability and logical indexing. What you want to achieve is something

Construct graph connectivity matrices in COO format

I have faced the following subtask while working with graph data: I need to construct graph connectivity matrices in COO format for graphs with several fully-connected components from arrays of “border” indices. As an example, given array the resulting COO matrix should be That is, borders array contains ranges of nodes that should form fully-connected subgraphs (starting index included and

Finding mean between two inputs from users

I’m trying to write a Python program using numpy, which prints the average/mean of all the even numbers bigger than 10 which are also between a specific lower and upper bound input by the user. So, if the user inputs 8 as the lower number and 16 as the upper number, then the output would be 14, but I can’t

NumPy + PyTorch Tensor assignment

lets assume we have a tensor representing an image of the shape (910, 270, 1) which assigned a number (some index) to each pixel with width=910 and height=270. We also have a numpy array of size (N, 3) which maps a 3-tuple to an index. I now want to create a new numpy array of shape (920, 270, 3) which

Advertisement