# Why Mathematica doesn't return a column? Kronecker product thinks it's a row, when it should be a column [duplicate]

I wanted to create the following matrix by using block partition of matrices.

$$\left[\begin{array}{c} I_D \otimes \text{Col}(K,1)\\ \vdots\\ I_D \otimes \text{Col}(K,T) \end{array}\right]$$

Let

D=2
B = {{1, 1}, {1, 4}}


I used at first this function:

mat[T_, K_] :=
ArrayFlatten[
Table[KroneckerProduct[IdentityMatrix[2], K[[;; , i]]], {i, 1,
T}]];


The problem with this function is that the result has some () where they shouldn't be...

We can see that from mat[2, B] // MatrixForm

I have this function which solves the problem

mat2[T_, K_] :=
Transpose[
ArrayFlatten[{Table[
KroneckerProduct[IdentityMatrix[2], K[[;; , i]]], {i, 1,
T}]}]];


When I do mat[2, B] // MatrixForm , I clearly see that the extra () have disappeared.

I think the problem starts with K[[;; , i]]] which returns a list which the kronecker thinks its a row, when I wanted a column...

Is there a way for K[[;; , i]]] to return a column?

## marked as duplicate by Carl Woll, José Antonio Díaz Navas, m_goldberg, Pinti, bbgodfreyNov 22 '18 at 17:00

• Both mat[;;, 1]] and mat[[1, ;;]] return a one-dimensional array (assuming that mat is a two-dimensional array). "Row" and "column" make no sense in this context. {1, 2, 3} is a vector. {{1, 2, 3}} and {{1},{2},{3}} are matrices, not vectors (even though they are sometimes confusingly referred to as row-vector and column-vector). Some other systems, such as MATLAB, do not support vectors at all, and will always return the matrix, thus they force the "row/column vector" distinction. Mathematica does not. – Szabolcs Nov 19 '18 at 12:57
• D has built-in meanings. Try to avoid starting one's own namings with capital letters in Mathematica. – Αλέξανδρος Ζεγγ Nov 19 '18 at 13:15
• the obvious answer to the last question is Transpose[{K[[;;,i]]}]; you could also try ArrayFlatten[{KroneckerProduct[iN, Transpose[{#}]]} & /@ Transpose[B]] as an alternative, where iN=IdentityMatrix[n] – user42582 Nov 19 '18 at 13:39
newmat[idim_Integer, oldmat_?MatrixQ] :=