<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sample(self, k=None, with_replacement=True, weights=None):
 """Return a new table where k rows are randomly sampled from the original table. Args: ``k`` -- specifies the number of rows (``int``) to be sampled from the table. Default is k equal to number of rows in the table. ``with_replacement`` -- (``bool``) By default True; Samples ``k`` rows with replacement from table, else samples ``k`` rows without replacement. ``weights`` -- Array specifying probability the ith row of the table is sampled. Defaults to None, which samples each row with equal probability. ``weights`` must be a valid probability distribution -- i.e. an array the length of the number of rows, summing to 1. Raises: ValueError -- if ``weights`` is not length equal to number of rows in the table; or, if ``weights`` does not sum to 1. Returns: A new instance of ``Table`` with ``k`` rows resampled. job | wage a | 10 b | 20 c | 15 d | 8 job | wage b | 20 b | 20 a | 10 d | 8 job | wage d | 8 b | 20 c | 15 a | 10 job | wage b | 20 c | 15 job | wage a | 10 a | 10 Traceback (most recent call last):
 ValueError: probabilities do not sum to 1 # Weights must be length of table. Traceback (most recent call last):
 ValueError: a and p must have same size """

        n = self.num_rows
        if k is None:
            k = n
        index = np.random.choice(n, k, replace=with_replacement, p=weights)
        columns = [[c[i] for i in index] for c in self.columns]
        sample = self._with_columns(columns)
        return sample