another little index puzzle
I have an array to be used for indexing. It is 2d, where the rows are all the permutations of some numbers. So: array([[-2, -2, -2], [-2, -2, -1], [-2, -2, 0], [-2, -2, 1], [-2, -2, 2], ... [ 2, 1, 2], [ 2, 2, -2], [ 2, 2, -1], [ 2, 2, 0], [ 2, 2, 1], [ 2, 2, 2]]) Here the array is 125x3 I want to select all the rows of the array in which all the 3 elements are equal, so I can remove them. So for example, the 1st and last row.
On Mon, Jan 21, 2013 at 2:41 PM, Neal Becker <ndbecker2@gmail.com> wrote:
I have an array to be used for indexing. It is 2d, where the rows are all the permutations of some numbers. So:
array([[-2, -2, -2], [-2, -2, -1], [-2, -2, 0], [-2, -2, 1], [-2, -2, 2], ... [ 2, 1, 2], [ 2, 2, -2], [ 2, 2, -1], [ 2, 2, 0], [ 2, 2, 1], [ 2, 2, 2]])
Here the array is 125x3
I want to select all the rows of the array in which all the 3 elements are equal, so I can remove them. So for example, the 1st and last row.
all_equal_mask = np.logical_and.reduce(arr[:,1:] == arr[:,:-1], axis=1) some_unequal = arr[~all_equal_mask] -- Robert Kern
On Mon, 2013-01-21 at 08:41 -0500, Neal Becker wrote:
I have an array to be used for indexing. It is 2d, where the rows are all the permutations of some numbers. So:
array([[-2, -2, -2], [-2, -2, -1], [-2, -2, 0], [-2, -2, 1], [-2, -2, 2], ... [ 2, 1, 2], [ 2, 2, -2], [ 2, 2, -1], [ 2, 2, 0], [ 2, 2, 1], [ 2, 2, 2]])
Here the array is 125x3
I want to select all the rows of the array in which all the 3 elements are equal, so I can remove them. So for example, the 1st and last row.
You can use a convolution to pick out the changes... conv_arr = numpy.array([[1, -1, 0], [0, 1, -1]]) equal_selector = ~numpy.any(numpy.dot(b, numpy.transpose(a)), 0) or unequal_selector = numpy.any(numpy.dot(b, numpy.transpose(a)), 0) hen
participants (3)
-
Henry Gomersall -
Neal Becker -
Robert Kern