Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Replace Elements of List Without Copying List' topicStudent Support Forum > General > Archives > "Replace Elements of List Without Copying List"

Next Comment >Help | Reply To Topic
Author Comment/Response
Don
01/06/12 7:59pm

It seems that in most cases where a list is modified in Mathematica, instead of updating the memory storing the list, a new list is created in memory, and the old reference is redirected to it. For very large lists, this makes it difficult to do list operations.

Question: How can I transform the elements of a list without making a new copy of that list?

Example:
Say I have a 3-dimensional array called "myList". It is large:

In[1]:= Dimensions[myList]
Out[1]:= {202, 384, 500}

Say I also have a 1-dimensional list called "myAdj".
It is the size of the third level of myList:

In[2]:= Dimensions[myAdj]
Out[2]:= {500}

I would like to subtract "myAdj" from every 2nd level element of "myList":

In[3]:=
Do[
Do[
myList[[i]][[j]] = myList[[i]][[j]] - myAdj,
{j, 384}],
{i, 202}]

URL: ,

Subject (listing for 'Replace Elements of List Without Copying List')
Author Date Posted
Replace Elements of List Without Copying List Don 01/06/12 7:59pm
Re: Replace Elements of List Without Copying List yehuda 01/07/12 4:37pm
Re: Replace Elements of List Without Copying List Nasser M. Ab... 01/07/12 4:52pm
Next Comment >Help | Reply To Topic