The overhead of the np.matrix class is quite high for small matrices. See for example the following code:

import time
import math
import numpy as np

def rot2D(phi):
    return np.matrix(c)

_b=np.matrix(np.zeros( (1,)))
def rot2Dx(phi):
    global _b
    r.itemset(0, c)
    return r


%timeit rot2D(phi)
%timeit rot2Dx(phi)

The second implementation performs much better by using a copy instead of a constructor. Is there a way to efficiency create a new np.matrix object? For other functions in my code I do not have the option to copy an existing matrix, but I need to construct a new object or perform a cast from np.array to np.matrix.

I am already aware of two alternatives:

- Using the new multiplication operator ( This is a good solution, but only python 3.5
- Using the .dot functions from np.array. This works, but personally I like the notation using np.matrix much better.

I also created an issue on github:

With kind regards,
Pieter Eendebak