# How to get a number, but not a list, of the dimension of your array?

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}.

-
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? – Rojolalalalalalalalalalalalala Feb 25 '13 at 12:14

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

-
This might be useful: mathematica.stackexchange.com/a/7922/8 – Verbeia Feb 25 '13 at 12:00