Message Boards Message Boards

0
|
5263 Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

What does List mean in the output?

After running a program I developed, I am analyzing part of it and get an output of,

2 List

What does the "List" mean here? I've searched the documentation with no answer found.

POSTED BY: Fred Diether
7 Replies
Posted 4 years ago

Fred,

nPP[[0]] is equivalent to Part[nPP, 0]. There might be a way to alter the definition of the built-in Part function to do what you want. A much simpler solution would be to shift the index values by one. Store the sum in nPP[[1]] , why does it have to be at nPP[[0]]?

POSTED BY: Rohit Namjoshi

Hi Rohit,

Thanks. Just for convenience of later programming. There are 720 indices. I suppose I could shift everything by 1 and make it 721. I will give it a shot.

POSTED BY: Fred Diether

Thanks. I think I got it. It was actually this with 720 list length for both

nPP[[0]] + nNN[[0]]

So I guess the "2" is there because there is two elements in the sum and "List" is there because there is nothing in the two Lists at 0. Does that sound correct?

POSTED BY: Fred Diether
Posted 4 years ago

Hi Fred,

Not exactly, expr[[0]] evaluates to the Head of expr, which is List in your example, not "nothing".

List + List
(* 2 List *)

(a*b)[[0]] + Sqrt[2][[0]]
(* Power + Times *)
POSTED BY: Rohit Namjoshi

Hi Rohit,

Ah, OK got it. But I need nPP[[0]] to contain a sum of elements of the programming and not be the Head. How can I do that? IOW, if the sum of the elements is 0 at npp[[0]], I need it to return 0 and not List.

POSTED BY: Fred Diether

Any expression may be used as the head of an expression. Thus,

a = 37[1, 2, 3]

is perfectly valid (although strange). Here, a[[0]] is the number 37. You may even mutate it with Set (=):

a[[0]]=33
a
(* 33[1, 2, 3] *)

Note, however, that vector operations will generally not recognize an object as a vector unless its head is List. You may recover the tail as a list by:

List@@a
(* {1, 2, 3} *)
POSTED BY: John Doty
Posted 4 years ago

Perhaps it is something like this

vector={3,4,5};
2*vector[[0]]

which returns

2 List

when

2*vector[[1]]

returns

6

because vector subscripts start at 1 in Mathematica and the 0'th element is the Head, which is List in this case.

POSTED BY: Bill Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract