MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Behavior of Array[]

  • To: mathgroup at
  • Subject: [mg19460] Re: [mg19444] Behavior of Array[]
  • From: "Wolf, Hartmut" <hwolf at>
  • Date: Sat, 28 Aug 1999 15:52:57 -0400
  • Organization: debis Systemhaus
  • References: <>
  • Sender: owner-wri-mathgroup at

Joseph C. Slater schrieb:
> I've been using Mathematica for many years and one thing still puzzles me.
> Elements of the array defined by the variable 'a' can be obtained using
> a[[i,j]]=expression. However, the command Array creates arrays comprised
> of elements named in the form 'a[i,j]'. Note the single brackets.
> Everything I see in the Mathematica book about brackets says that these
> are functions. This seems inconsistant to me. Shouldn't they be listed as
> 'a[[i,j]]' until they are defined? What are the single brackets supposed
> to mean if not elements of the array 'a'?

Hello Joseph,

the term "array" is not used consistently in _Mathematica_ with what you
know from languages like Fortran or C. There it means a storage
structure of contiguous storage elements, which you can index into
through some adress calculation (the compiler usually does that, but you
may do it yourself). Not so with Mathematica. There the term "array" is
only (occasionally) used in a very loose sense, and S.Wolfram (always?)
puts it into apostrophes. (See index of The Book, also section 2.4.5).
So in Mathematica this only means something to index into. As such both

   a[[i,j]]      and    f[i,j]

might be understood as arrays. If you look at the FullForm...

In[10]:= a[[i, j]] // FullForm
Out[10]//FullForm= Part[a, i, j] see the first one is a shortcut for the function Part which gives
part of an expression.  Most often this is used for expressions with
head List and you might fantasize this as beeing an "array" (or array of
pointers, as in C e.g.) but what it "really" is, is hidden behind the
curtain (of the implementation).

The FullForm of f[i,j] gives nothing new, it is simply an expression
with head f and elements i and j, nothing more -- not yet a function.
Only if you have prior made a definition like

   f[x_, y_]:= some expression 
               (which usually contains x and y and other functions and

then you might "think" of it as being a function, in reality it's a
replacement rule which the evaluator applies whenever appropriate.

Otherwise you might have made definitions like

   f[<i>,<j>] = some constant expression

If you have made multiple such definitionss consistently for some range
(of integers) for <i> and <j> as in

In[12]:= Do[ f[i, j] = i*j , {i, 3}, {j, 0, 1}]
In[13]:= ?f

then you might 'think' of this as being an "array". (This is often used
with dynamic programming). But you usually do not access with Part. That
isn't forbidden either, but

In[15]:= Hold[f[3, 1]][[1, 2]]
...just gives the (argument?, index?) ...
Out[15]= 1
In[16]:= List[a, b][[2]]
Out[16]= b

To remind, 

In[20]:= f[3, 1]
Out[20]= 3

There happens to be a certain function called Array (since "array" is
not a term of _Mathematica_ it might be called so) which just does what
is specified (see help).

Kind regards, hw

  • Prev by Date: Ctrl-space no good (ver 3 or 4, Windows 98)
  • Next by Date: Re: Simultaneous nonlinear Regression of two data sets
  • Previous by thread: Behavior of Array[]
  • Next by thread: Re: Behavior of Array[]