Ok, I know how to transpose a matrix, with for instance:
A = np.arange(25).reshape(5, 5)
print A
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
A.T
array([[ 0, 5, 10, 15, 20],
[ 1, 6, 11, 16, 21],
[ 2, 7, 12, 17, 22],
[ 3, 8, 13, 18, 23],
[ 4, 9, 14, 19, 24]])
In the case of unidimensional arrays, it's not possible to use this ".T" tool (I don't know why, honestly) so to transpose a vector you have to change the paradigm and use, for instance:
B = np.arange(5)
print B
array([0, 1, 2, 3, 4])
and because B.T
would give the same result, we, applying this change of paradigm, use:
B[ :, np.newaxis]
array([[0],
[1],
[2],
[3],
[4]])
and I find this change of paradigm a little bit antiesthetic because a 1-D vector is in no way a different entity to a 2-D vector (a matrix), in the sense that mathematically speaking they come from the same family and share many things.
My question is: is it possible to do this tranposition with the (sometimes called) jewel of the crown of numpy that is einsum, in a more compact and unifying way for every kind of tensor? I know that for a matrix you do
np.einsum('ij->ji', A)
and you get, as previosuly with A.T
:
array([[ 0, 5, 10, 15, 20],
[ 1, 6, 11, 16, 21],
[ 2, 7, 12, 17, 22],
[ 3, 8, 13, 18, 23],
[ 4, 9, 14, 19, 24]])
is it possible to do it with 1-D arrays?
Thank you in advance.