All problems
Cross-Entropy Nats to Bits
Problem
Convert a cross-entropy measured in nats into bits by dividing by ln(2), which is the same as multiplying by log2(e). One nat equals about 1.4427 bits, and a cross-entropy of 0.0 stays 0.0.
Hint
Change of base: log2(x) = ln(x) / ln(2).
Test cases
case 1
in: [1]
expected: 1.4426950408889634
case 2
in: [0.6931471805599453]
expected: 1
case 3
in: [0]
expected: 0
case 4
in: [10]
expected: 14.426950408889635
Starter codePython
import math
def cross_entropy_bits_from_nats(nats):
# Your code here
pass4 test cases · run your code against them in the editor