简体   繁体   中英

How to reshape 2D arrays?

I would like to reshape four 2D arrays : A, B, C and D (i have split before a "big array" in order to minimize function...and these arrays are the analytical results of the minimization) in a specific order :

AB

CD

I try with np.reshape or vectorize then concatenate but impossible to get this order as you can see of the picture below, all is mixed. I should have a result homogeneous

在此处输入图片说明

Thanks for answer, it works well by this way!

And i must apply that on a great number of subarrays, so i would like to automize the reshape of the array, as example below, the case of 4 arrays. As you can see i try with loops for but it doesnt work and perhaps by this way it could be not very fast...

test_reshape = np.empty([20,20])


test_reshape[0:10,0:10] = frametemperature[0,:,:]
test_reshape[0:10,10:10*2.] = frametemperature[1,:,:]

test_reshape[10:10*2.,0:10] = frametemperature[2,:,:]
test_reshape[10:10*2.,10:10*2.] = frametemperature[3,:,:]



for i in range(frametemperature.shape[0]/2):
    for j in range(frametemperature.shape[0]/2):
        for k in range(frametemperature.shape[0]): 
            test_reshape[i*10:10*(i+1),j*10:10*(j+1)] = frametemperature[k,:,:]

So you've got 4 2d arrays that you want to combine back into one 2d array.

1) create a empty 2d array to store them in

import numpy as np
blank = np.empty([4,4])

2) assign the arrays according to their location instead of concatenating

A = np.ones([2,2])
B = np.ones([2,2]) * 2
C = np.ones([2,2]) * 3
D = np.ones([2,2]) * 4
blank[0:2,0:2] = a
blank[0:2,2:4] = b
blank[2:4,0:2] = c
blank[2:4,2:4] = d
blank

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM