# Matrix of given size with unspecified elements

I want to generate a Matrix of given size whose elements are not specified

I can use

Array[a, {3, 2}]


to get

{{a[1, 1], a[1, 2]}, {a[2, 1], a[2, 2]}, {a[3, 1], a[3, 2]}}


however i would like to have

{{a[[1, 1]], a[[1, 2]]}, {a[[2, 1]], a[[2, 2]]}, {a[[3, 1]], a[[3, 2]]}}

-
Can you explain why you want to do this, what is your use case? It seems that this question might be based on a misunderstanding ... – Szabolcs Jul 11 '14 at 19:34

You can do this with Inactive like this

temp = Array[Inactive[Part][a, #1, #2] &, {3, 2}];


you can then set an a at a later stage and Activate that:

a = RandomReal[{-1, 1}, {4, 4}];
Activate[temp]

-

If you are using version 10 you can make use of the new Indexed function:

expr1 = Array[Indexed[a, {##}] &, {3, 2}]


If you are on an older version you can Quiet the error messages and use:

expr2 = Quiet @ Array[a[[##]] &, {3, 2}]

{{a[[1, 1]], a[[1, 2]]}, {a[[2, 1]], a[[2, 2]]}, {a[[3, 1]], a[[3, 2]]}}


With either expression, if a is later assigned a value, or substituted with ReplaceAll, the extractions will be made:

a = CharacterRange["a", "z"] ~Partition~ 2;


Now:

expr1

expr2

{{"a", "b"}, {"c", "d"}, {"e", "f"}}

{{"a", "b"}, {"c", "d"}, {"e", "f"}}

-