Packs the dates into a single Tensor. The Tensor has shape `date_tensor.shape() + (3,)`, where the last dimension represents years, months and days, in this order. This can be convenient when the dates are the final result of a computation in the graph mode: a `tf.function` can ret
(self)
| 178 | return self._ordinals |
| 179 | |
| 180 | def to_tensor(self): |
| 181 | """Packs the dates into a single Tensor. |
| 182 | |
| 183 | The Tensor has shape `date_tensor.shape() + (3,)`, where the last dimension |
| 184 | represents years, months and days, in this order. |
| 185 | |
| 186 | This can be convenient when the dates are the final result of a computation |
| 187 | in the graph mode: a `tf.function` can return `date_tensor.to_tensor()`, or, |
| 188 | if one uses `tf.compat.v1.Session`, they can call |
| 189 | `session.run(date_tensor.to_tensor())`. |
| 190 | |
| 191 | Returns: |
| 192 | A Tensor of shape `date_tensor.shape() + (3,)`. |
| 193 | |
| 194 | #### Example |
| 195 | |
| 196 | ```python |
| 197 | dates = tff.datetime.dates_from_tuples([(2019, 1, 25), (2020, 3, 2)]) |
| 198 | dates.to_tensor() # tf.Tensor with contents [[2019, 1, 25], [2020, 3, 2]]. |
| 199 | ``` |
| 200 | """ |
| 201 | return tf.stack((self.year(), self.month(), self.day()), axis=-1) |
| 202 | |
| 203 | def day_of_year(self): |
| 204 | """Calculates the number of days since the beginning of the year. |