Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download

Jupyter notebook binaryStrings.ipynb

Project: NYCWiC
Views: 106
Kernel: Python 3 (Anaconda)

Binary Strings

import numpy as np import matplotlib.pyplot as plt
def binString(n): binS = np.random.randint(0,2,100) s = ''.join(map(str,binS)) return s def rle(s): current = s[0] count = 0 runLength = [] for char in s: if char == current: count += 1 else: runLength.append(count) current = char count = 1 runLength.append(count) return np.array(runLength) def binStringHist(s): rl = rle(s) plt.hist(rl) plt.show()
s1 = binString(100) binStringHist(s1)
Image in a Jupyter notebook
s2 = '0010101011101010101010101010101010101001010101010101010100100101010111010101010101010100101000101010' binStringHist(s2)
Image in a Jupyter notebook