# C2_W4_Lab_1_WeatherData: Q/A on how to index target size

At the end of the notebook, I didn’t understand how you’re indexing the temperature labels to get the singular temperature 12 hours into the future. But in asking the question, I was able to answer all my questions but as I had already type everything up, I figured I would post it anyway.

The `map_features_target` function creates the `targets` but I also didn’t understand the indexing that is going on, mainly I didn’t understand the indexing of `elements[-1:,-1]` in the function below.

``````def map_features_target(elements):
features = elements[:HISTORY_SIZE]
target = elements[-1:,-1]
return (features, target)
``````

I infer the first index is the time dimension as you’re grabbing 120 elements with the features indexing of ` elements[:HISTORY_SIZE]`. I guess I understand then in the line

``````target = elements[-1:,-1]
``````

how the `[-1:` in the first (aka time) dimension does grab the temperature 12 hours into the future because the total window size is: `HISTORY_SIZE + FUTURE_TARGET` (720 + 12) so the final index in this window will be the final time 12 hours in the future.

And since the first dimension is time, then the second index would be within the 13 individual features like `Day cos` and `VPdef`. If the final position in the second index (`-1]`) refers to the `T (degC)` feature, then this `-1` indexing make sense.

Now the thing I still really didn’t get was what the colon was doing in the target time index`[-1:,`, so I decided to look at the labels with and without the colon. With the colon, the shapes and the temperature target value in the first batch is:

``````Shape of input features for a batch: (72, 120, 13, 1)
Shape of targets for a batch: (72, 1, 1)
tf.Tensor([[0.1051584]], shape=(1, 1), dtype=float32)
``````

And, if instead you remove the colon in the `map_features_target` function you get the output:

``````Shape of input features for a batch: (72, 120, 13, 1)
Shape of targets for a batch: (72, 1)
tf.Tensor([0.1051584], shape=(1,), dtype=float32)
``````

You get the same value, but the targets are missing a dimension. The colon isn’t indexing any further values (which it couldn’t because it was by definition taking the final value in the first dimension, so maybe should have seen that coming) but instead is adding a middle dimension to the label tensor.

So, I did answer my questions, and I figured I would post this anyway.

Hi @dzubke

great contribution. Thanks !

Happy continuation of the specialization and hope to see more contribution like this one.

Thanks, @luigisaetta!

I’m excited to dive into course 3 and will be sure to contribute more like this.

1 Like

The part that made it confusing to me is due to the variable naming.

``````features = elements[:HISTORY_SIZE]
``````

doesn’t get the features. It gets the historical data, i.e. including the features and the target value ‘T (degC)’