I have a list of 2x1
matrices like:
JavaScript
x
2
1
[[[2.3], [2.4]], [[1.7], [1.6]], [[2.02], [2.33]]]
2
I need to convert it into a tuple of tuples, like:
JavaScript
1
2
1
((2.3,2.4),(1.7,1.6),(2.02,2.33))
2
I know I can loop through the list and convert it manually , trying to check if there is a better-optimized way of doing it.
Advertisement
Answer
You can do it this way using numpy indexing and slicing that outer dimension.
JavaScript
1
4
1
ma = [[[2.3], [2.4]], [[1.7], [1.6]], [[2.02], [2.33]]]
2
ama=np.array(ma) #incase it wasn't a numpy array since you mentioned numpy in tags
3
tuple(map(tuple,ama[:, :, 0].tolist()))
4
Output:
JavaScript
1
2
1
((2.3, 2.4), (1.7, 1.6), (2.02, 2.33))
2