Linked Questions

79 votes
3 answers
171k views

How can I remove duplicate rows of a 2 dimensional numpy array? data = np.array([[1,8,3,3,4], [1,8,9,9,4], [1,8,3,3,4]]) The answer should be as follows: ans = ...
Roman's user avatar
  • 3,251
7 votes
3 answers
3k views

I have 3D numpy array and I want only unique 2D-sub-arrays. Input: [[[ 1 2] [ 3 4]] [[ 5 6] [ 7 8]] [[ 9 10] [11 12]] [[ 5 6] [ 7 8]]] Output: [[[ 1 2] [ 3 4]] [[ 5 6] [...
Petr's user avatar
  • 115
3 votes
1 answer
6k views

I have a set of discretized coordinates in a Nx2 numpy.ndarray. I would like to get the counts and indices of each of these unique coordinate sets. numpy.unique does exactly this, but for scalar ...
M.T's user avatar
  • 5,271
1 vote
3 answers
786 views

I'm very badly stuck, and every pythonista I've asked can't seem to help. I'm using vstack to create an array of vectors in a loop like this: Corr = np.vstack((Corr, S)) I need to remove repeating ...
user3625380's user avatar
5 votes
1 answer
2k views

In numpy, is there a nice idiomatic way of testing if all rows are distinct in a 2d array? I thought I could do len(np.unique(arr)) == len(arr) but this doesn't work at all. For example, arr = np....
Simd's user avatar
  • 21.5k
-1 votes
1 answer
1k views

I have a 2D np array containing str values. I would like to get a count of the unique arrays (rows) that make up this 2D array. This would be the example input: array([[A, B, C], [A, B, C], ...
msalkind's user avatar
2 votes
1 answer
229 views

My problem is that my data isn't a good representation of what is really going on because it has a lot of duplicate rows. Consider the following- a b 1 23 42 2 23 42 3 23 42 4 14 ...
Ravaal's user avatar
  • 3,369
3 votes
1 answer
573 views

I have some simple code and I just want to count the number of distinct columns in the product of two matrices. The code is import numpy as np import itertools n = 5 h = 2 M = np.random.randint(2, ...
marshall's user avatar
  • 2,493
0 votes
1 answer
138 views

How can I efficiently iterate over all h by n arrays made of 0s and 1s where all the rows and all the columns are distinct? At the moment I do this. h = 10 n = 15 hxn = np.arange(h*n).reshape(h, -1) ...
marshall's user avatar
  • 2,493
0 votes
1 answer
77 views

I want to iterate over an array of arrays and skip to the next array if I've already read the same array. The following code works, but I'm searching a more 'pythonic' style solution. from sklearn ...
user3420714's user avatar
-1 votes
3 answers
71 views

I have a list A containing an array with indices. I want to print all the unique index numbers by scanning each [i,j]. In [0,3], i=0,j=3. I present the expected output. import numpy as np A=[np.array([...
Klimt865's user avatar
1 vote
0 answers
62 views

Let's consider a 2d-array A 2 3 5 7 2 3 5 7 1 7 1 4 5 8 6 0 2 3 5 7 The first, second and last lines are identical. The algorithm I'm looking for should return an 2d-...
sol's user avatar
  • 1,500
47 votes
2 answers
74k views

I have a DataFrame that has duplicated rows. I'd like to get a DataFrame with a unique index and no duplicates. It's ok to discard the duplicated values. Is this possible? Would it be a done by ...
Adam Greenhall's user avatar
34 votes
8 answers
17k views

I have an array X: X = np.array([[4, 2], [9, 3], [8, 5], [3, 3], [5, 6]]) And I wish to find the index of the row of several values in ...
Octoplus's user avatar
  • 483
32 votes
5 answers
23k views

I have an image img: >>> img.shape (200, 200, 3) On pixel (100, 100) I have a nice color: >>> img[100,100] array([ 0.90980393, 0.27450982, 0.27450982], dtype=float32) Now my ...
wal-o-mat's user avatar
  • 7,374

15 30 50 per page
1
2 3 4 5
7