0

So basically I have an array, that consists of 14 rows and 426 Columns, every row represents one property of a dog and every column represents one dog, now I want to know how many dogs are ill, this property is represented by the 14. row. 0 = Healthy and 1 = ill, so how do I count the specific row?

I tried to use the numpy.count_nonzero but this counts the values of the entire array, is there a way to tell it to only count a specific row?

0

2 Answers 2

1

You can simply sum the values of the 14.row and you get the number (count) of ill dogs:

count = A[13,:].sum() # number of ill dogs -- 13 because the index starts with 0
Sign up to request clarification or add additional context in comments.

Comments

1

Suppose we have this vector:

>import numpy as np
>arr = np.arange(30).reshape(6,5)
>arr
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29]])

With this, you will get the sum of all values for a specific row:

>np.sum(arr[1,:]) #On row 1
35

For your specific case, use:

>np.sum(arr[13,:])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.