<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self, data):
 """Write samples to an output stream. As much as one blocksize of audio data will be played without blocking. If more than one blocksize was provided, the function will only return when all but one blocksize has been played. Data will be converted to a numpy matrix. Multichannel data should be provided as a (frames, channels) matrix. If the data is provided as a 1-dim array, it will be treated as mono data and will be played on all channels simultaneously. If the data is provided as a 2-dim matrix and fewer tracks are provided than channels, silence will be played on the missing channels. Similarly, if more tracks are provided than there are channels, the extraneous channels will not be played. """

        frames = len(data)
        _, channels = _split(self.channels)
        _, dtype = _split(self.dtype)

        if (not isinstance(data, np.ndarray) or data.dtype != dtype):
            data = np.array(data, dtype=dtype)
        if len(data.shape) == 1:
            # play mono signals on all channels
            data = np.tile(data, (channels, 1)).T
        if data.shape[1] > channels:
            data = data[:, :channels]
        if data.shape < (frames, channels):
            # if less data is available than requested, pad with zeros.
            tmp = data
            data = np.zeros((frames, channels), dtype=dtype)
            data[:tmp.shape[0], :tmp.shape[1]] = tmp

        data = data.ravel().tostring()
        err = _pa.Pa_WriteStream(self._stream, data, frames)
        self._handle_error(err)