Registered Member
|
Hi,
For some reason the sum of a boolean array is always 1, regardless of the entries, any idea why? How do I get the number of 1s in it? Thanks.
|
Moderator
|
A boolean is either 0 or 1, so the result of any operation on boolean must be either 0 or 1. For your use case, you can either lazily cast to int:
Y.cast<int>().sum(); or use: Y.count(); |
Registered Member
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]