Python/Numpy: rearrange N4xN3xN2xN1 4D array into an (N4.N2)x(N3.N1) 2D array

P-Gn

For example, if:

a = numpy.array([[[[1,2],[3,4]],[[5,6],[7,8]]],[[[11,12],[13,14]],[[15,16],[17,18]]]])

then I would like to eventually obtain:

1  2  5  6
3  4  7  8
11 12 15 16
13 14 17 18

Simple reshaping won't work unfortunately.

Alex Riley

You need to swap the second and third axes first, and then reshape:

>>> a.swapaxes(1, 2).reshape(4, 4)
array([[ 1,  2,  5,  6],
       [ 3,  4,  7,  8],
       [11, 12, 15, 16],
       [13, 14, 17, 18]])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

numpy dot or einsum for multiplying N 2x2 arrays with a 2xn array

From Dev

numpy standardize 2D subsets of a 4D array

From Dev

Multiply 2d matrix with 3d array to get 4d array for component scores

From Dev

Rearrange columns of numpy 2D array

From Dev

Rearrange string into 2D array python

From Dev

Reshape 4d numpy array to 2d array while preserving array locations

From Dev

How to reshape 4d array to 2d array in numpy

From Dev

Intuition and idea behind reshaping 4D array to 2D array in NumPy

From Dev

Get a 3D or 4D array as input and reshape it to 2D array in a function from external script

From Dev

Adding 3D array to 4D array

From Dev

Write an algorithm which will evaluate Pn (x) = (N + 1)xn + N x n - 1 + ... + 2x + 1

From Dev

How to perform iterative 2D operation on 4D numpy array

From Dev

How to perform iterative 2D operation on 4D numpy array

From Dev

How to convert 4d RGB image data to 2d array for LogisticRegression

From Dev

Access an element in a Multidimensional (3D and 4D) array

From Dev

Given two numbers n1 and n2 as input, return an array containing all the primes between n1 and n2

From Dev

Need a way of storing a 4D array

From Dev

Store a 4D array in a Vector?

From Dev

Python - Sum 4D Array

From Dev

Read 4D Array in MEX File

From Dev

Read 4D Array in MEX File

From Dev

Optimize 4D Numpy array construction

From Dev

Filtering a 4D numpy array

From Dev

2d boolean array using n^2 bits of space

From Dev

Read set of images into 4D Numpy array with dimension (num_img,channel, dim1, dim2)

From Dev

The mean of the mean of the Xn combinations by n. is the mean of the Xn

From Dev

4d np.array() acting like a 1d np.array()

From Dev

Indexing a 4D array using another array of 3D indices

From Dev

How can I save 3D array results to a 4D array in Python/numpy?

Related Related

  1. 1

    numpy dot or einsum for multiplying N 2x2 arrays with a 2xn array

  2. 2

    numpy standardize 2D subsets of a 4D array

  3. 3

    Multiply 2d matrix with 3d array to get 4d array for component scores

  4. 4

    Rearrange columns of numpy 2D array

  5. 5

    Rearrange string into 2D array python

  6. 6

    Reshape 4d numpy array to 2d array while preserving array locations

  7. 7

    How to reshape 4d array to 2d array in numpy

  8. 8

    Intuition and idea behind reshaping 4D array to 2D array in NumPy

  9. 9

    Get a 3D or 4D array as input and reshape it to 2D array in a function from external script

  10. 10

    Adding 3D array to 4D array

  11. 11

    Write an algorithm which will evaluate Pn (x) = (N + 1)xn + N x n - 1 + ... + 2x + 1

  12. 12

    How to perform iterative 2D operation on 4D numpy array

  13. 13

    How to perform iterative 2D operation on 4D numpy array

  14. 14

    How to convert 4d RGB image data to 2d array for LogisticRegression

  15. 15

    Access an element in a Multidimensional (3D and 4D) array

  16. 16

    Given two numbers n1 and n2 as input, return an array containing all the primes between n1 and n2

  17. 17

    Need a way of storing a 4D array

  18. 18

    Store a 4D array in a Vector?

  19. 19

    Python - Sum 4D Array

  20. 20

    Read 4D Array in MEX File

  21. 21

    Read 4D Array in MEX File

  22. 22

    Optimize 4D Numpy array construction

  23. 23

    Filtering a 4D numpy array

  24. 24

    2d boolean array using n^2 bits of space

  25. 25

    Read set of images into 4D Numpy array with dimension (num_img,channel, dim1, dim2)

  26. 26

    The mean of the mean of the Xn combinations by n. is the mean of the Xn

  27. 27

    4d np.array() acting like a 1d np.array()

  28. 28

    Indexing a 4D array using another array of 3D indices

  29. 29

    How can I save 3D array results to a 4D array in Python/numpy?

HotTag

Archive