0

Calculate mean of bool array

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

27th Jun 2021, 12:21 PM
Noah
Noah - avatar
3 Respostas
+ 4
Noah , please show us a sample array, and what you expect as output. thanks!
27th Jun 2021, 1:00 PM
Lothar
Lothar - avatar
+ 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 ;)
27th Jun 2021, 1:21 PM
visph
visph - avatar
+ 1
True is 1, False is 0 So if you summed True + False it would be 1 + 0
27th Jun 2021, 2:03 PM
Lisa
Lisa - avatar