def METHOD_NAME(data: np.ndarray, timeout: int, last_frame: np.array):
    """
    Generic WARLS packet encoding
    Max LEDs: 255
    Header: [1, timeout]
    Byte 	Description
    2 + n*4 	LED Index
    3 + n*4 	Red Value
    4 + n*4 	Green Value
    5 + n*4 	Blue Value
    """
    packet = bytearray([1, (timeout or 1)])
    byteData = data.astype(np.dtype("B"))
    if last_frame is None or data.shape != last_frame.shape:
        last_frame = np.full(data.shape, np.nan)
    """
    for i in range(len(byteData)): # loop through byteData
        if not np.array_equal(last_bytes[i], byteData[i]): # if index has changed from last sent frame
            packet.extend(bytes([i]))   # add index as first byte
            packet.extend(byteData[i].flatten().tobytes())
    """  # do above in numpy
    # get indexes of pixels that have changed
    idx = np.flatnonzero(np.any(last_frame != data, axis=1))
    # make a new output array
    out = np.zeros((len(idx), 4), dtype="B")
    # first byte of each pixel is the index
    out[:, 0] = idx
    # final three bytes are the pixel values
    out[:, 1:] = byteData[idx]
    # convert out to bytes to send
    packet.extend(out.flatten().tobytes())
    return packet