Question: Is there a way to plot a chart by joining the points as they appear in the input array instead of ordering the array by x-axis asc before joining the points.
For instance:

```
Input Array= [[1, 3], [5, 6], [4, 4], [3, 10]]

```

All the chart frameworks I have examined (jqplot, flot, et al) will sort the Array by x-axis before joining the points. Resulting in:

```
[1, 3] -> [3, 10] -> [4, 4] -> [5, 6]

```

But what I want is to join the points as they appear exactly in the input Array.

```
[1, 3] -> [5, 6] -> [4, 4] -> [3, 10]

```

If you plot these few points as I stated you will observe what I mean. They look different. There is a need that I have to join the points as they appear in the input array and not ordered by x-axis ascending.
Any hint will be greatly appreciated.

Answer: 
If you are having to make a Python function call to produce each of the matrices you want to multiply, then you are basically screwed performance-wise. But if you can vectorize the `transform_step_to_4by4` function, and have it return an array with shape `(n, 4, 4)` then you can save some time using `matrix_multiply`:

```
import numpy as np
from numpy.core.umath_tests import matrix_multiply

matrices = np.random.rand(64, 4, 4) - 0.5

def mat_loop_reduce(m):
    ret = m[0]
    for x in m[1:]:
        ret = np.dot(ret, x)
    return ret

def mat_reduce(m):
    while len(m) % 2 == 0:
        m = matrix_multiply(m[::2], m[1::2])
    return mat_loop_reduce(m)

In [2]: %timeit mat_reduce(matrices)
1000 loops, best of 3: 287 us per loop

In [3]: %timeit mat_loop_reduce(matrices)
1000 loops, best of 3: 721 us per loop

In [4]: np.allclose(mat_loop_reduce(matrices), mat_reduce(matrices))
Out[4]: True

```

You now have log(n) Python calls instead of n, good for a 2.5x speed-up, which will get close to 10x for n = 1024. Apparently `matrix_multiply` is a ufunc, and as such has a `.reduce` method, which would allow your code to run no loops in Python. I have not been able to make it run though, keep getting an arcane error:

```
In [7]: matrix_multiply.reduce(matrices)
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
RuntimeError: Reduction not defined on ufunc with signature

```
I can't compare the speed to your method since I don't know how you turn your `(60,6)` array into a `(4,4)`, but this works to take the dot of a sequence:

```
A = np.arange(16).reshape(4,4)
B = np.arange(4,20).reshape(4,4)
C = np.arange(8,24).reshape(4,4)

arrs = [A, B, C]

P = reduce(np.dot, arrs)

```

And this is equivalent to, but should be faster than:

```
P = np.identity(4, dtype = arrs[0].dtype)
for arr in arrs:
    P = np.dot(P, arr)

```

Timing test:

```
In [52]: def byloop(arrs):
   ....:     P = np.identity(4)
   ....:     for arr in arrs:
   ....:         P = np.dot(P, arr)
   ....:     return P
   ....: 

In [53]: def byreduce(arrs):
   ....:     return reduce(np.dot, arrs)
   ....: 

In [54]: byloop(arrs)
Out[54]: 
array([[  5104,   5460,   5816,   6172],
       [ 15728,  16820,  17912,  19004],
       [ 26352,  28180,  30008,  31836],
       [ 36976,  39540,  42104,  44668]])

In [55]: byreduce(arrs)
Out[55]: 
array([[ 5104,  5460,  5816,  6172],
       [15728, 16820, 17912, 19004],
       [26352, 28180, 30008, 31836],
       [36976, 39540, 42104, 44668]])

```

where `len(arrs) = 1000`:

```
In [56]: timeit byloop(arrs)
1000 loops, best of 3: 1.26 ms per loop

In [57]: timeit byreduce(arrs)
1000 loops, best of 3: 656 us per loop

```