I want to count the number of equal matrices that I encounter after splitting a large matrix.
mat1 = np.zeros((4, 8))
split4x4 = np.split(mat1, 4)
Now I want to know how many equal matrices are in split4x4, but collections.Counter(split4x4)
throws an error. Is there a built-in way in numpy to do this?
This can be done in a fully vectorized manner using the numpy_indexed package (disclaimer: I am its author):
import numpy_indexed as npi
unique_rows, row_counts = npi.count(mat1)
This should be substantially faster than using collections.Counter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With