Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to use the dimension of a certain array, to use it as a bounder in a loop afterwards. The problem is that I get a list, when write :

Dimensions[ai]= {2}

aiod = Table[ai[[i]] - 1, {i, 1, Dimensions[ai], 1}]

and it does not work. I need to get "2" instead of {2}.

share|improve this question
You can use Part, as in {2}[[1]]. – b.gatessucks Feb 25 '13 at 10:01
Or Length, if the first (outermost) dimension is what you want. – Verbeia Feb 25 '13 at 10:12
What is your first line Dimensions[ai]={2} intended to do? – Rojo Feb 25 '13 at 12:14
up vote 2 down vote accepted

Assuming the first (outermost) dimension is what you want, use Length:

aiod = Table[ai[[i]]-1, {i, Length[ai]}]

Notice I've used a simpler iterator specification.

Anyway, if this is your real problem, then be aware that arithmetic operations in Mathematica are Listable, so you can just write

ai - 1
share|improve this answer
This might be useful: – Verbeia Feb 25 '13 at 12:00

Your Answer


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.