I have an image and the vertexs of each sides of it, meaning that, if we see each side as a segment (A,B) i have both the A and B point coordinates. Now i would like to crop the image so that i have only one segment of the image (which is the side), for example That’s just one side
Tag: numpy
Grouping two variables based on third variable bins in python
My intension is to group two variables pairs falling within a third variable’s bin interval. such as: So that I can fetch a XY pair for a particular bin range of third variable, e.g., bin of 25-50 For the same, I tried to sort the “Z” variable and accordingly “X” and “Y” variables, with Z, Y, X = zip(*sorted(zip(Z,Y,X))), that
Select a string which has given value on a particular position
I have a ndarray which looks like this example: I need to pick values from the second column, whose corresponding values in the first column matches particular criteria. Example criteria: second and third position of the string (in first column) are equal to zero. If this is true, take a copy of the corresponding values in the second column and
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (3,)
I have an np.ndarray of shape (5, 5, 2, 2, 2, 10, 8) named table. I can succesfully slice it like this: But for some reason when I try to specify three values for dimension 5 (of length 10) like this: I get: The same is for: This does not happen with: which output the correct result. I tried to
Binomial distributions (Bernoulli trials) with different probabilities
I want to speed up the code below – namely the for loop. Is there a way to do it in numpy? More explanations – I want to generate N sequences of Bernoulli trials (ie. 0s and 1s, called throws) where each sequence has a mean (probability p) given by values in another array (mu_throws). This can be sampled from
3d numpy array perform operation along column i only
I have a 3d numpy array like this (as an example) I want to apply the following operations only to elements within the column with index 1 in the inner dimension. The elements are [-2,6,10,14] for the example above. The operations would be: Can someone help me? I have looked into several NumPy methods but can’t seem to adapt to
How to get NumPy array of n last/first Trues in each row
I have a broadcasted array, which is sorted rowly, and a masked array. I want to get the last n elements (or the first n ones) of each row which are True i.e.: Do we have to split the array (using np.cumsum(np.sum(mask, axis=1))), pad and …? What will be the best way to do this just with NumPy? Answer Using
Find boundary points of xy coordinates
I have a text file with xy-coordinates called xy.txt. I read the file using and I can plot the points with Visually the data looks as follows: I want to retrieve the xy-coordinates of the points that form the boundary of the shape. Answers on similar questions suggest to use Concave Hull. With the help of this blog I write
python iterate over arrays matrices
I am trying to create a new matrix(array) where I have been scouring the documentation in numpy but can’t find a function to satisfy this. Answer You’re looking for numpy.matmul. You’ll need to make the vectors have two dimensions (with a size of one in one of the dimensions). For example:
subtracting time intervals from column dates in dataframes Pandas Python
How would I be able to subtract 1 second and 1 minute and 1 month from data[‘date’] column? Answer Your date column is of type string. Convert it to pd.Timestamp and you can use pd.DateOffset: