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

```
For matrices this small, it might be advantageous to avoid using BLAS altogether. There are small matrix multiplication libraries out there, for example [libSMM](http://www.hector.ac.uk/cse/distributedcse/reports/cp2k03/cp2k03/node9.html) (there are more).

It might be doable to wrap them with f2py or cython, or --- it might be easier to roll your own, in cython or fortran/f2py.