Repeat copies of array elements: Run-length decoding in MATLAB

Problem Statement We have an array of values, vals and runlengths, runlens: vals = [1,3,2,5] runlens = [2,2,1,3] We are needed to repeat each element in vals times each corresponding element in runlens. Thus, the final output would be: output = [1,1,3,3,2,5,5,5] Prospective Approach One of the fastest tools with MATLAB is cumsum and is … Read more

Difference between map, applymap and apply methods in Pandas

Straight from Wes McKinney’s Python for Data Analysis book, pg. 132 (I highly recommended this book): Another frequent operation is applying a function on 1D arrays to each column or row. DataFrame’s apply method does exactly this: In [116]: frame = DataFrame(np.random.randn(4, 3), columns=list(‘bde’), index=[‘Utah’, ‘Ohio’, ‘Texas’, ‘Oregon’]) In [117]: frame Out[117]: b d e … Read more