Skip to content

Tag: numpy

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 correspon…

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 thi…

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: