1

I have an array of 2d arrays like

+------+    +------+
|      |    |      |
|  A   |    |  B   |
|      |    |      |
+------+    +------+

and I want to "delete" the outermost parentheses, as in to get

+------+------+
|      |      |
|  A   |  B   |
|      |      |
+------+------+

for example I have

[[[1,1,1],[2,2,2]],[[3,3,3],[4,4,4]]]

and I want to get

[[1,1,1,3,3,3],[2,2,2,4,4,4]]

in other words, I need to make an array of shape (7,3,1000) into (3,7000) by appending those 7 in chain

how to go about it?

1 Answer 1

2

One approach with swapping of axes between first and second ones and then reshape to merge the last two axes -

arr.swapaxes(0,1).reshape(arr.shape[1],-1)

Sample run -

In [9]: arr = np.array([[[1,1,1],[2,2,2]],[[3,3,3],[4,4,4]]])

In [10]: arr.swapaxes(0,1).reshape(arr.shape[1],-1)
Out[10]: 
array([[1, 1, 1, 3, 3, 3],
       [2, 2, 2, 4, 4, 4]])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.