Bitwise operations on strings lil_matrix

How to quickly extract two rows of scipy.sparse.lil_matrix and apply bitwise operations to them? I tried:

np.bitwise_and(A[1,:], A[2,:])

      

but NumPy seems to want to have an array type according to the documentation.

+2


a source to share


1 answer


By "lil_matrix", do you mean scipy.sparse.lil_matrix? If so, you will have to convert your sparse array to a regular dense array in order to perform bitwise operations on it, I suppose.

a = np.asarray(A.todense())
np.bitwise_and(a[1,:], a[2,:])

      



Should do the trick I think ...

EDIT: Forgot the "asarray" in there ...

+3


a source







All Articles