Let a be a list in python.
a = [1,2,3]
When the transpose of the matrix is applied to a , we get:
np.matrix(a).transpose() matrix([[1], [2], [3]])
I want to generalize this functionality and will further illustrate what I want to do with an example. Let b be another list.
b = [[1, 2], [2, 3], [3, 4]]
In a list items: 1, 2, and 3. I would like to consider each of [1,2] , [2,3] and [3,4] as list items in b , just for the purpose of doing this transpose. I would like the result to be as follows:
array([[[1,2]], [[2,3]], [[3,4]]])
In general, I would like to be able to specify what the list item will look like and perform matrix transformation based on this.
I could just write a few lines of code to do this, but my goal is to ask this question to find out if there is a built-in numpy function or a pythonic way to do this.
EDIT: the output of unutbu below corresponds to the output that I have above. However, I wanted to find a solution that would work in a more general case. I posted another input / output below. My initial example was not descriptive enough to convey what I wanted to say. Let the elements in b be [1,2] , [2,3] , [3,4] and [5,6] . Then the result below will transpose the matrix on the elements of higher dimension. More generally, as soon as I describe how the “element” will look, I would like to know if there is a way to do something like transpose.
Input: b = [[[1, 2], [2, 3]], [[3, 4], [5,6]]] Output: array([[[1,2], [3,4]], [[2,3], [5,6]]])