Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]]}}
share|improve this question
    
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 at 19:34

2 Answers 2

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]
share|improve this answer

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

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

enter image description here

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"}}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.