Skip to content

Instantly share code, notes, and snippets.

@amar-enkhbat
Last active July 11, 2019 12:46
Show Gist options
  • Select an option

  • Save amar-enkhbat/f3f71554917a75557381a46fc6bd4b09 to your computer and use it in GitHub Desktop.

Select an option

Save amar-enkhbat/f3f71554917a75557381a46fc6bd4b09 to your computer and use it in GitHub Desktop.
演習問題7
import numpy as np
probs = np.array([0.3, 0.2, 0.15, 0.15, 0.1, 0.1])
result = np.array([])
for prob in probs:
result = np.append(result, probs * prob)
print(result)
code_len = np.array([3, 4, 4, 4, 5, 5, 4, 5, 5, 5, 6, 6, 5, 5, 6, 6, 6, 6, 5, 5, 6, 6, 6, 6, 5, 6, 6, 6, 7, 7, 5, 6, 6, 6, 7, 7])
log_side = np.log2(1./result)
H = np.sum(result * log_side)
L = np.sum(result * code_len)
print("H =", H)
print("L =", L)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment