Ok, in trying to answer this question I came across something very strange.
matrix = np.zeros(10000)
matrix[np.random.choice(10000, 100)] = np.random.rand(100)
matrix = matrix.reshape(10, 1000)
from scipy.sparse import lil_matrix
l = lil_matrix(matrix.T)
l.rows
Out: array([[], [], [], ..., [], [], []], dtype=object)
Ok, so I want to know which rows have data, so I tried:
np.any(l.rows)
Out: [8]
. . . what?
out = np.any(l.rows)
type(out)
Out: list
It's a list. With an 8 in it. Which seems . . . random. What is going on?
After playing around it seems it returns the first object
in the array that's not []
.
np.random.seed(9)
matrix = np.zeros(10000)
matrix[np.random.choice(10000, 100)] = np.random.rand(100)
matrix = matrix.reshape(10, 1000)
from scipy.sparse import lil_matrix
l = lil_matrix(matrix.T)
l.rows
Out: array([[], [], [5], ..., [], [], []], dtype=object)
np.any(l.rows)
Out: [5]
But considering np.any
is only supposed to output boolean
or np.array
of boolean, this is a very strange result. Does anyone know why this happens?