0
Data = matrix R

First I wanted to count elements of each row

countR = np.count_nonzero(R, axis=1)

Then, I could get matrix countR.

[25  2  1  2  2 55  1  2  1  2  1  1  2  2  1  1  1  1  2  2  1  2 14  1  3 ..

Second, I want to count elements in matrix "if element>1 "

So what I did is here

countR1 = pd.value_counts(countR.values, sort>1)

But there was an error.

How can i count elements?

DYZ
  • 55,249
  • 10
  • 64
  • 93

2 Answers2

1

you can do it easily like this:

y=np.array(countR)
len(y[y>1])
Daniyal Ahmed
  • 715
  • 5
  • 11
0

if I understand correctly you want to count all the elements that are larger than 1 in the matrix R.

you can filter the data-frame by doing so(to dispose of the elements that are larger than 1):

biggerThanOne = R[R<1]

you can then get the size of the array and get the number of elements:

biggerThanOne.size

if you mean you want to count the elements of countR you can practically do the same thing

Yuval Raz
  • 96
  • 7