开发者

after slicing matrix, how to average between connecting arrays

开发者 https://www.devze.com 2022-12-07 22:35 出处:网络
I have a matrix A of size 256x256. I have divided it in 16 arrays of 32 by 32, keeping its original array connections.

I have a matrix A of size 256x256.

I have divided it in 16 arrays of 32 by 32, keeping its original array connections.

Then I want to average the border of each array with its adjacent connection.


Let's say, we have a matrix A of size 12x12, (then I want 16 chunks of 3x3) I am using blockshaped ( Slice 2d array into smaller 2d arrays) 开发者_C百科to slice the matrix

np.random.seed(365)
c = np.arange(144).reshape((12, 12))

L=blockshaped(c, 3, 3)


Visually:

c=[[ 0   1   2 |  3   4   5  | 6   7   8   | 9  10  11]
  [ 12  13  14 | 15  16  17  | 18  19  20  | 21  22  23]
  [ 24  25  26 | 27  28  29  | 30  31  32  | 33  34  35]
------------------------------------------------------
  [ 36  37  38 | **39  40  41**  | 42  43  44  | 45  46  47]
  [ 48  49  50 | **51  52  53**  | 54  55  56  | 57  58  59]
  [ 60  61  62 | **63  64  65**  | 66  67  68  | 69  70  71]
------------------------------------------------------
  [ 72  73  74 | 75  76  77  | 78  79  80  | 81  82  83]
  [ 84  85  86 | 87  88  89  | 90  91  92  | 93  94  95]
  [ 96  97  98 | 99 100 101  | 102 103 104 | 105 106 107]
------------------------------------------------------
  [108 109 110 | 111 112 113 | 114 115 116 | 117 118 119]
  [120 121 122 | 123 124 125 | 126 127 128 | 129 130 131]
  [132 133 134 | 135 136 137 | 138 139 140 | 141 142 143]]

If I take the chuck marked with **

39  40  41
51  52  53
63  64  65

How can I average the value of the boundaries?

39 40 41 with 27 28 29

63 64 65 with 75 76 77

and

39 51 63 with 38 50 62 41 53 65 with 42 57 69

any ideas will help me a lot

0

精彩评论

暂无评论...
验证码 换一张
取 消