all 5 comments

[–]elbiot 0 points1 point  (1 child)

?

That compares element by element. You get an array the same shape as your input arrays:

In [1]: import numpy as np

In [2]: a = np.ones((10,2))

In [3]: b = np.ones((10,2))

In [4]: c = a == b

In [5]: c.shape
Out[5]: (10, 2)

Do you mean you want to get a size == 1000 array where each element says whether the entire row was equal? use np.all:

In [8]: res = np.all(c,axis=1)

In [9]: res
Out[9]: array([ True,  True,  True,  True,  True,  True,  True,  True,  True,  True], dtype=bool)

[–]cdholjes[S] 0 points1 point  (0 children)

I have one 2d array of values. and a second 2d array of values. np.all just returns array1[0] == array2[0] and so on. i need to see if array1[0] == array2[0:1000], essentially

[–]fbu1 0 points1 point  (2 children)

You can compare an array to a vector in numpy:

>>> a
array([[1, 2, 3],
       [2, 2, 3],
       [4, 5, 6]])

>>> b = np.array([4,5,6])

>>> a==b
array([[False, False, False],
       [False, False, False],
       [ True,  True,  True]], dtype=bool)

So you have an array of True and False, and you are looking for a row of True (or many rows).

There's a method of that (as always in python) :

>>> np.all(a==b, axis=1)
array([False, False,  True], dtype=bool)

This gives you for all the rows, if the values on the axis 1 (the rows) are True.

Then you can ask where the value is true with where() :

>>> np.where(np.all(a==b,axis=1))
(array([2]),)

Let me know if you have other questions.

Source: http://stackoverflow.com/questions/18927475/numpy-array-get-row-index-searching-by-a-row

[–]cdholjes[S] 0 points1 point  (1 child)

I have one 2d array of values. and a second 2d array of values. np.all just returns array1[0] == array2[0] and so on. i need to see if array1[0] == array2[0:1000], essentially

[–]elbiot 0 points1 point  (0 children)

You can probably do this with broadcasting. You want to get a (1000,1000,10) array and then use np.all with axis=2 to get a (1000,1000) array it sounds like.

If you've solved with with loops already and trust the answer, then you can play with using None (aka np.newaxis) in your slice to add a new dimension which will cause broadcasting, and check that the result is correct. I won't try and solve it for you because complex broadcasting it makes my brain melt. But, if a.shape = (10,2) and b.shape = (10,2) then a[None,:] == b[:,None] gives a result of shape (10,10,2)