2021年3月27日星期六

Convert 3x3 array of 2x2 arrays to a 6x6 array maintaining position

I have a 3x3x4 array, each of the 3x3 subarrays (4-tuples, or 1x4 arrays) I want to map to a 2x2 array and stitch them together to form a 6x6 array. I'm having difficulty explaining this in words, so I hope the below illustration helps:

Here's a 3x3 array of 1x4 arrays, named 1 through 9:

1 2 3  4 5 6  7 8 9  

Each 1x4 array above is enumerated below:

1 = [a, b, c, d]  2 = [e, f, g, h]  3 = [i, j, k, l]  4 = [m, n, o, p]  5 = [q, r, s, t]  6 = [u, v, w, x]  7 = [y, z, !, @]  8 = [#, $, %, ^]  9 = [&, *, (, )]  

I want to convert this 3x3x4 array to a bigger 6x6 array:

a b e f i j  c d g h k l  m n q r u v  o p s t w x  y z # $ & *  ! @ % ^ ( )  

You'll see the top-left 2x2 corresponds to the 1st 1x4 array, the top-center 2x2 is the 2nd 1x4 array, and so on.

enter image description here

As in the image above, 1 became a b c d in a 2x2 sub-array, 2 became e f g h i in a 2x2 sub-array. These are part of the larger 6x6 array.

I'm not sure programmatically how to do this, any ideas?

Here's some starter code:

#!/usr/bin/env python3    from random import uniform    # original array is 3x3  old_width = 3  old_height = 3  # subarray size  sub_width = 2  sub_height = 2  # new array is function of the above four  new_width = old_width*sub_width  new_height = old_height*sub_height    def rand_subarray():    # makes a 1x4 subarray    return [uniform(0.00, 1.00) for _ in range(sub_width*sub_height)]    def generate_map():    # makes a 3x3 array of 1x4 subarrays    return [[rand_subarray() for _ in range(old_width)] for _ in range(old_height)]    if __name__ == '__main__':    map = generate_map()  

If it makes a difference, this is for a self organizing map.

https://stackoverflow.com/questions/66837098/convert-3x3-array-of-2x2-arrays-to-a-6x6-array-maintaining-position March 28, 2021 at 07:32AM

没有评论:

发表评论