F64 generates a histogram of counts of values within given number of bins and min / max range. hist vals is sized to nBins. if value is < min or > max it is ignored.
(hist *[]float64, vals []float64, nBins int, min, max float64)
| 17 | // number of bins and min / max range. hist vals is sized to nBins. |
| 18 | // if value is < min or > max it is ignored. |
| 19 | func F64(hist *[]float64, vals []float64, nBins int, min, max float64) { |
| 20 | *hist = slicesx.SetLength(*hist, nBins) |
| 21 | h := *hist |
| 22 | // 0.1.2.3 = 3-0 = 4 bins |
| 23 | inc := (max - min) / float64(nBins) |
| 24 | for i := 0; i < nBins; i++ { |
| 25 | h[i] = 0 |
| 26 | } |
| 27 | for _, v := range vals { |
| 28 | if v < min || v > max { |
| 29 | continue |
| 30 | } |
| 31 | bin := int((v - min) / inc) |
| 32 | if bin >= nBins { |
| 33 | bin = nBins - 1 |
| 34 | } |
| 35 | h[bin] += 1 |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // F64Table generates an table with a histogram of counts of values within given |
| 40 | // number of bins and min / max range. The table has columns: Value, Count |