0

I was viewing this page with some numpy exercises. Exercise 65 goes like this:

Consider two arrays A and B of shape (8,3) and (2,2). How to find rows of A that contain elements of each row of B regardless of the order of the elements in B ?

# Author: Gabe Schwartz

A = np.random.randint(0,5,(8,3))
B = np.random.randint(0,5,(2,2))

C = (A[..., np.newaxis, np.newaxis] == B)
rows = (C.sum(axis=(1,2,3)) >= B.shape[1]).nonzero()[0]
print(rows)

Can someone explain to me what A[..., np.newaxis, np.newaxis] is doing? I've never seen ... in python, ever.

On a separate note, what does ... normally do in python?

hlin117
  • 20,764
  • 31
  • 72
  • 93
  • 4
    Calling myself out on duplication: http://stackoverflow.com/questions/772124/what-does-the-python-ellipsis-object-do – hlin117 Nov 07 '15 at 19:58
  • http://stackoverflow.com/questions/772124/what-does-the-python-ellipsis-object-do – Tim D Nov 07 '15 at 19:58

0 Answers0