Last active
March 31, 2016 01:22
-
-
Save dela3499/17ed394ac4f81d41870f1d9d241e9a8b to your computer and use it in GitHub Desktop.
Pattern of set bits in range of binary numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
%matplotlib inline | |
x = np.arange(256).astype(np.uint8) | |
y = np.array(map(lambda x: np.unpackbits([x]).sum(), x)) | |
figsize(10,5) | |
plt.step(x,y,'k', linewidth = 1) | |
plt.axis([-2,257,0,8.2]) | |
label('Number', '# set bits', '# set bits for range of numbers') |
Author
dela3499
commented
Mar 31, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment