Make time series_from_array() more intuitive to use
Hi @James-Tipping ,

The API is working as intended.
```
tf.keras.utils.timeseries_dataset_from_array(
    data,
    targets,
    sequence_length,
    sequence_stride=1,
    sampling_rate=1,
    batch_size=128,
    shuffle=False,
    seed=None,
    start_index=None,
    end_index=None
)
```
Suppose for below code:
```
x = np.zeros((10, 3))
y = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
test = keras.utils.timeseries_dataset_from_array(x[:-4], y[4:], sequence_length=4, batch_size=2000)
```
Here data is x[:-4] means data of 6 Rows and 3 columns. With `sequence_length=4` and default `sequence_stride=1`  and 
`sampling_rate=1` we can get 3 data points (6-4+1=3) and for these data points the target indices are y[4:] i.e. starting from index-4 to next 3 i.e. upto index-6 which are `[5,6,7]` respectively.

Hence the first data point will be: 
```
array([[0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.]]
```
and corresponding target point is `5`.

I am not sure why you are expecting other result. Could you please explain what is misleading here ?
 This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Hi @SuryanarayanaY, thank you for your reply.

The issue is that timeseries_dataset_from_array is touted as a replacement for TimeseriesGenerator, when in fact they have different outputs. In fact, I would argue the output from TimeseriesGenerator is the expected result.

Looking above at my examples, it is clear in this case that I require 6 different outputs, and not 3 outputs.

Take the example of someone predicting stock market closing values. If we have data points for 120 days, and we want to use the previous 30 days as input, it's intuitive that there would be 90 (120 - 30) input sets, and 90 output sets of data. This isn't the case with timeseries_dataset_from_array.

I came across this by following the (very well written) documentation for timeseries_dataset_from_array, as it was recommended instead of TimeseriesGenerator. Thus, either the documentation could be changed to reflect that they do not produce the same results, or the implementation could be changed.

Please feel free to correct me if I'm misunderstanding. Hi @James-Tipping ,

There is implementation differences between `timeseries_dataset_from_array` and `TimeseriesGenerator` APIs. 


From `timeseries_dataset_from_array` API , the `targets` should be:


targets | Targets corresponding to timesteps in data. targets[i] should be the target corresponding to the window that starts at index i (see example 2 below). Pass None if you don't have target data (in this case the dataset will only yield the input data).
-- | --

```
x = np.zeros((10, 3))
y = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
test1 = keras.utils.timeseries_dataset_from_array(x, y[4:], sequence_length=4)
print(list(test1.as_numpy_iterator()))
```
Here the argument data(i.e. 'x') is of length 10, where as targets(y[4:]) is of length '6' and  no of data points series data points generated from the input data 'x' which depends upon the values passed to `sequence_length`, `sequence_stride` , `sampling_rate` etc. Also

Whereas  `TimeseriesGenerator` the `targets` should be:


targets | Targets corresponding to timesteps in data. It should have same length as data.
-- | --

This means we need to supply the data of same length corresponding to input timesteps.

Consider this example code below:

```
x = np.zeros((10, 3))
y = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
test2 = keras.preprocessing.sequence.TimeseriesGenerator(x, y, length=4) #This works
test2[0]

test2 = keras.preprocessing.sequence.TimeseriesGenerator(x, y[4:], length=4) #This fails
```

With the API `timeseries_dataset_from_array` we have more flexibility than that of `TimeseriesGenerator`. Hence `timeseries_dataset_from_array` not exactly same copy as `TimeseriesGenerator` but with some more additional flexibility.

Thanks!




 This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Feature Request

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

2.10.0 (Tensorflow-macos)

### Custom Code

Yes

### OS Platform and Distribution

MacOS 13.2.1

### Mobile device

_No response_

### Python version

3.10.8

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

TimeseriesGenerator() is deprecated, and Tensorflow docs encourage the use of time series_from_array() instead. However, this is not intuitive to use, requiring far more boilerplate code to achieve the same effect.

In addition, the results are not as expected. I spent hours debugging my code to realise time series_from_array() is not behaving as expected. Using the code below, I would expect there to be 6 different inputs and outputs, however, there are only 3. Running the same code with TimeseriesGenerator(), without the [:-4] and [4:] indexing, produces the expected 6 inputs and outputs.


### Standalone code to reproduce the issue

```shell
x = np.zeros((10, 3))
y = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

test = keras.utils.timeseries_dataset_from_array(x[:-4], y[4:], sequence_length=4, batch_size=2000)
list(test.as_numpy_iterator())
```


### Relevant log output

```shell
[(array([[[0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.]],
  
         [[0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.]],
  
         [[0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.]]]),
  array([5, 6, 7]))]
```

### Code for TimeseriesGenerator() (expected output)

```Python
test = keras.preprocessing.sequence.TimeseriesGenerator(x, y, length=4)
test[0]
```

### Expected output

```shell
(array([[[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]],
 
        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]],
 
        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]],
 
        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]],
 
        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]],
 
        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]]]),
 array([ 5,  6,  7,  8,  9, 10]))
```

</details>