MathGroup Archive 2003

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

Search the Archive

RE: how come ? (Setting Array Values)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41122] RE: [mg41115] how come ? (Setting Array Values)
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 4 May 2003 03:55:12 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Phuong,

The Mathematica Help for Part seems to be misleading here. It says...

"Part[expr, i, j, ? ] is equivalent to expr[[i]] [[j]]" and
"You can make an assignment like t[[i]] = value to modify part of an
expression. "

Help doesn't mention using t[[i,j,...]] = value for assignment but you can
clearly use it. So you might think it would be equivalent to the form you
tried.


The following works...

l = {{1, 2, 3}, {2, 4, 5}}
l[[2,3]] = 3
3

Part[l, 2, 3] = 5
5

But

l[[2]][[3]] = 3   (* or *)
Part[Part[l, 2], 3] = 3

give errors.

I think that is because Mathematica expects a Symbol as the first argument
of the outer Part statement. It won't search for the symbol at a depth
greater than 1. It's a feature. But since you can use the other form it is
not a serious problem.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: Phuong [mailto:phuongdt at writeme.com]
To: mathgroup at smc.vnet.net

Hi everybody,

I am a newbie in Mathematica and began programming with it. Could
anyone explain this problem to me ?

why mathematica can't deal with

l={{1,2,3},{2,4,5}}

l[[1]][[2]]=3

and here is its error message :
Set::"setps": "\!\(l \[LeftDoubleBracket] 1 \[RightDoubleBracket]\) in
\
assignment of part is not a symbol."

but it can with

Part[l,1,2]=3




  • Prev by Date: How change $AddOnsDirectory
  • Next by Date: Re: how come ?
  • Previous by thread: Re: Re: Re: How change $AddOnsDirectory
  • Next by thread: Wave guides