It flattens one dimensions of the x
array (I think the code assumes x
is a 2D array) and removes every occurence of the integer k
. For example:
>>> import numpy as np
>>> x = np.arange(20).reshape(4, 5) # makes it a 2D array
>>> x
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]])
>>> k = 4
>>> inds = np.array([b for a in x for b in a if not b==k])
>>> inds
array([ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
Note that your code isn't really using the powerful and fast NumPy functionality. If x
is an array you could simply use:
>>> x[x!=k] # make it 1D and keep only values != k
array([ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])