Helper to extract features for one data point.

def _extract_features(self, sequence1, sequence2):
        """ Helper to extract features for one data point. """

        array1 = np.array(tuple(sequence1), ndmin=2).T
        array2 = np.array(tuple(sequence2), ndmin=2)

        K = (len(self._binary_features) 
             + sum(num_feats for _, num_feats in self._sparse_features))

        feature_array = np.zeros((array1.size, array2.size, K), dtype='float64')

        for k, feature_function in enumerate(self._binary_features):
            feature_array[..., k] = feature_function(array1, array2)

        if self._sparse_features:
            n_binary_features = len(self._binary_features)

            for i, j in np.ndindex(len(sequence1), len(sequence2)):
                k = n_binary_features

                for feature_function, num_features in self._sparse_features:
                    
                    feature_array[i, j, k + feature_function(i, j, sequence1, sequence2)] = 1.0
                    k += num_features

        return feature_array