I have a 2d numpy array that contains tuple with two elements: an int and an str.
An example on how the 2d array may look:
matrix = np.array(
[[(1, 'foo'), (), (4, 'bar')],
[(),(),()],
[(1, 'foo'), (), (3, 'foobar')],
[(),(),()]],
dtype=object)
I'm looking to remove the lines that contains only empty tuples.
I tried the following code:
matrix = matrix[~np.all(matrix == (), axis=1)]
but it gave me the following error:
numpy.AxisError: axis 1 is out of bounds for array of dimension 0
The above code works for a 2d array that contains only integers with a condition like that in the all function: matrix == 0.
It correctly removes all lines that contains only zeros. So is there a way to do that but instead of removing lines with only zeros, to remove lines with only empty tuples?