generate functionTue, 28 Feb 2023

Using Numpy, write an array coding function (Run-Length Encoding). The function of repetition of elements compresses the function into one element and considers the number of repetitions. The function returns a motorcade of two Numpy veins of the same length. The first contains elements, and the second - how many times they need to be repeated.

def RLE(array): inds = np.add.reduceat(np.not_equal(array[1:], array[:-1]), np.arange(len(array))) array = array[inds] lens = np.diff(np.append(inds, len(array))) return array, lens

Questions about programming?Chat with your personal AI assistant