# Create AffineTransform with ArrayFlatten

**URL:** <https://community.wolfram.com/t/create-affinetransform-with-arrayflatten/20512>\
**Category:** Questions\
**Created:** [August 9, 2022, 12:58am UTC](https://community.wolfram.com/t/create-affinetransform-with-arrayflatten/20512 "2022-08-09T00:58:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hongyizhao](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@hongyizhao](https://community.wolfram.com/u/hongyizhao)\
**Post date:** [August 9, 2022, 12:58am UTC](https://community.wolfram.com/t/create-affinetransform-with-arrayflatten/20512/1 "2022-08-09T00:58:46Z")

</div>

I want to obtain the same result given by **AffineTransform** but use **ArrayFlatten**. I tried the following example, but it didn’t produce the desired results:

```
In[81]:= aa = {IdentityMatrix[3], {2, 3, 4}};
AffineTransform[{aa[[1]], aa[[2]]}] // TransformationMatrix
ArrayFlatten[{{aa[[1]], {{0, 0, 0}}}, {{aa[[2]]} // Transpose, 1}}]

Out[82]= {{1, 0, 0, 2}, {0, 1, 0, 3}, {0, 0, 1, 4}, {0, 0, 0, 1}}

During evaluation of In[81]:= ArrayFlatten::match: ArrayFlatten[{{{{1,0,0},{0,1,0},{0,0,1}},{{0,0,0}}},{{{2},{3},{4}},1}}] fails the matching condition for ArrayFlatten[a,n]: if b = a[[i_1,i_2,...,i_n]], c = a[[j_1,j_2,...,j_n]], Head[a] == Head[b] == Head[c], Length[Dimensions[b]] >= n, Length[Dimensions[c]] >= n, and i_k = j_k, then Dimensions[b][[k]] must equal Dimensions[c][[k]]. Here the condition fails for k = 1 and i_k = j_k = 1.

Out[83]= ArrayFlatten[{{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{0, 0, 
     0}}}, {{{2}, {3}, {4}}, 1}}]

```

Any hints for solving this problem?

Regards,  
Zhao

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [August 9, 2022, 2:17am UTC](https://community.wolfram.com/t/create-affinetransform-with-arrayflatten/20512/2 "2022-08-09T02:17:03Z")

</div>

This seems like a sort of awkward thing to do, but here’s one attempt:

```
ArrayPad[ArrayPad[aa[[1]], {{0, 1}, {0, 0}}], {{0, 0}, {0, 1}}, List /@ Append[aa[[2]], 1]]

```

---

<div class="post-metadata">

**Author:** ![hongyizhao](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@hongyizhao](https://community.wolfram.com/u/hongyizhao)\
**Post date:** [August 9, 2022, 3:21am UTC](https://community.wolfram.com/t/create-affinetransform-with-arrayflatten/20512/3 "2022-08-09T03:21:59Z")

</div>

The following method does the trick:

```
In[128]:= aa = {IdentityMatrix[3], {2, 3, 4}};
AffineTransform[{aa[[1]], aa[[2]]}] // TransformationMatrix
ArrayFlatten[{
  {aa[[1]], {aa[[2]]} // Transpose}, {{{0, 0, 0}}, 1}
  }]
% == %%

Out[129]= {{1, 0, 0, 2}, {0, 1, 0, 3}, {0, 0, 1, 4}, {0, 0, 0, 1}}

Out[130]= {{1, 0, 0, 2}, {0, 1, 0, 3}, {0, 0, 1, 4}, {0, 0, 0, 1}}

Out[131]= True

```

---

<div class="post-metadata">

**Author:** ![hongyizhao](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@hongyizhao](https://community.wolfram.com/u/hongyizhao)\
**Post date:** [August 10, 2022, 2:33am UTC](https://community.wolfram.com/t/create-affinetransform-with-arrayflatten/20512/4 "2022-08-10T02:33:41Z")

</div>

Here are some further examples:

```
ArrayFlatten[{
   {IdentityMatrix[2]}, {1}
   }] // MatrixForm
ArrayFlatten[{
      {IdentityMatrix[2], 1}
      }] // MatrixForm
ArrayFlatten[{
         {Array[a, {1, 2}], Array[b, {1, 3}]},
   {Array[c, {4, 2}], Array[d, {4, 3}]}
         }] // MatrixForm

```

 ![Selection_096.png](https://global.discourse-cdn.com/wolfram/original/3X/0/a/0a79624d356f18ef0cb00c9fc4c9996ea4e4db5f.png)

In short, the key points are as follows: the dimensions of the rows and columns of the corresponding matrix block must correspond to each other.
