I have a large sequence of vectors of length N. I need some unsupervised learning algorithm to divide these vectors into M segments.

For example:

![enter image description here](https://i.stack.imgur.com/O1hyC.png)

K-means is not suitable, because it puts similar elements from different locations into a single cluster.

Update:

The real data looks like this:

![enter image description here](https://i.stack.imgur.com/VyVCU.png)

Here, I see 3 clusters: `[0..50], [50..200], [200..250]`

Update 2:

I used modified k-means and got this acceptable result:

![enter image description here](https://i.stack.imgur.com/WBlZn.png)

Borders of clusters: `[0, 38, 195, 246]`