This list creates an array of (5,3) objects:
In [47]: nptest=np.array(test) In [49]: nptest.shape Out[49]: (5, 3) In [50]: nptest.dtype Out[50]: dtype('O') In [51]: nptest[:,0] Out[51]: array([list([0]), list([0]), list([1]), list([2]), list([2])], dtype=object)
The first column is an array of (1d) lists. In my new version of numpy , more explicit.
Performing an equality test in an array or even a list of lists is not easy. After trying a few things, I found this:
In [52]: arow = nptest[:,0] In [56]: [x[0]==1 for x in arow] Out[56]: [False, False, True, False, False] In [57]: mask = [x[0]==1 for x in arow] In [58]: nptest[mask,:] Out[58]: array([[list([1]), array([[ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.], ..., [ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.]]), array([2, 2])]], dtype=object)
Or we could turn an array of lists into an array of numbers:
In [60]: np.array(arow.tolist()) Out[60]: array([[0], [0], [1], [2], [2]]) In [61]: np.array(arow.tolist())==1 Out[61]: array([[False], [False], [ True], [False], [False]], dtype=bool)
Or check [1] instead of 1. Contains matching lists, not their contents.
In [64]: [x==[1] for x in arow] Out[64]: [False, False, True, False, False]