Skip to content
Advertisement

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

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:

Advertisement