<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def data_struct_array(sample, **vectors):
 # data_struct_array(sample, *, energy, **vectors):
 """Combine samples and per-sample data into a numpy structured array. Args: sample (array_like):
 Samples, in any form that can be converted into a numpy array. energy (array_like, required):
 Required keyword argument. Energies, in any form that can be converted into a numpy 1-dimensional array. **kwargs (array_like):
 Other per-sample data, in any form that can be converted into a numpy array. Returns: :obj:`~numpy.ndarray`: A numpy structured array. Has fields ['sample', 'energy', 'num_occurrences', **kwargs] """

    if not len(sample):
        # if samples are empty
        sample = np.zeros((0, 0), dtype=np.int8)
    else:
        sample = np.asarray(sample, dtype=np.int8)

        if sample.ndim < 2:
            sample = np.expand_dims(sample, 0)

    num_samples, num_variables = sample.shape

    if 'num_occurrences' not in vectors:
        vectors['num_occurrences'] = [1] * num_samples

    datavectors = {}
    datatypes = [('sample', np.dtype(np.int8), (num_variables,))]

    for kwarg, vector in vectors.items():
        dtype = float if kwarg == 'energy' else None
        datavectors[kwarg] = vector = np.asarray(vector, dtype)

        if len(vector.shape) < 1 or vector.shape[0] != num_samples:
            msg = ('{} and sample have a mismatched shape {}, {}. They must have the same size '
                   'in the first axis.').format(kwarg, vector.shape, sample.shape)
            raise ValueError(msg)

        datatypes.append((kwarg, vector.dtype, vector.shape[1:]))

    if 'energy' not in datavectors:
        # consistent error with the one thrown in python3
        raise TypeError('data_struct_array() needs keyword-only argument energy')
    elif datavectors['energy'].shape != (num_samples,):
        raise ValueError('energy should be a vector of length {}'.format(num_samples))

    data = np.rec.array(np.zeros(num_samples, dtype=datatypes))

    data['sample'] = sample

    for kwarg, vector in datavectors.items():
        data[kwarg] = vector

    return data