Calculate mean of bool array | Sololearn: Learn to code for FREE!

0

Calculate mean of bool array

How do you calculate the mean of a bool array?! For example [True,False,False,False,True]

6/27/2021 12:21:52 PM

Noah

3 Answers

New Answer

+4

Noah , please show us a sample array, and what you expect as output. thanks!

+1

you could compute the mean of a bool array, but you'll get a float in range 0, 1 as result (by adding 0 or 1 values abd dividing by array length)... not a boolean (int 0 or 1)... however, you could get the nearest boolean from the mean by rounding it ;)

+1

True is 1, False is 0 So if you summed True + False it would be 1 + 0